| 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 | 6 |
| 7 #include "google_apis/gcm/engine/checkin_request.h" | 7 #include "google_apis/gcm/engine/checkin_request.h" |
| 8 #include "google_apis/gcm/monitoring/fake_gcm_stats_recorder.h" | 8 #include "google_apis/gcm/monitoring/fake_gcm_stats_recorder.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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 } | 47 } |
| 48 | 48 |
| 49 const uint64 kAndroidId = 42UL; | 49 const uint64 kAndroidId = 42UL; |
| 50 const uint64 kBlankAndroidId = 999999UL; | 50 const uint64 kBlankAndroidId = 999999UL; |
| 51 const uint64 kBlankSecurityToken = 999999UL; | 51 const uint64 kBlankSecurityToken = 999999UL; |
| 52 const char kCheckinURL[] = "http://foo.bar/checkin"; | 52 const char kCheckinURL[] = "http://foo.bar/checkin"; |
| 53 const char kChromeVersion[] = "Version String"; | 53 const char kChromeVersion[] = "Version String"; |
| 54 const uint64 kSecurityToken = 77; | 54 const uint64 kSecurityToken = 77; |
| 55 const char kSettingsDigest[] = "settings_digest"; | 55 const char kSettingsDigest[] = "settings_digest"; |
| 56 const char kEmailAddress[] = "test_user@gmail.com"; |
| 57 const char kTokenValue[] = "token_value"; |
| 56 | 58 |
| 57 class CheckinRequestTest : public testing::Test { | 59 class CheckinRequestTest : public testing::Test { |
| 58 public: | 60 public: |
| 59 enum ResponseScenario { | 61 enum ResponseScenario { |
| 60 VALID_RESPONSE, // Both android_id and security_token set in response. | 62 VALID_RESPONSE, // Both android_id and security_token set in response. |
| 61 MISSING_ANDROID_ID, // android_id is missing. | 63 MISSING_ANDROID_ID, // android_id is missing. |
| 62 MISSING_SECURITY_TOKEN, // security_token is missing. | 64 MISSING_SECURITY_TOKEN, // security_token is missing. |
| 63 ANDROID_ID_IS_ZER0, // android_id is 0. | 65 ANDROID_ID_IS_ZER0, // android_id is 0. |
| 64 SECURITY_TOKEN_IS_ZERO // security_token is 0. | 66 SECURITY_TOKEN_IS_ZERO // security_token is 0. |
| 65 }; | 67 }; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 117 |
| 116 void CheckinRequestTest::CreateRequest(uint64 android_id, | 118 void CheckinRequestTest::CreateRequest(uint64 android_id, |
| 117 uint64 security_token) { | 119 uint64 security_token) { |
| 118 // First setup a chrome_build protobuf. | 120 // First setup a chrome_build protobuf. |
| 119 chrome_build_proto_.set_platform( | 121 chrome_build_proto_.set_platform( |
| 120 checkin_proto::ChromeBuildProto::PLATFORM_LINUX); | 122 checkin_proto::ChromeBuildProto::PLATFORM_LINUX); |
| 121 chrome_build_proto_.set_channel( | 123 chrome_build_proto_.set_channel( |
| 122 checkin_proto::ChromeBuildProto::CHANNEL_CANARY); | 124 checkin_proto::ChromeBuildProto::CHANNEL_CANARY); |
| 123 chrome_build_proto_.set_chrome_version(kChromeVersion); | 125 chrome_build_proto_.set_chrome_version(kChromeVersion); |
| 124 | 126 |
| 125 CheckinRequest::RequestInfo request_info( | 127 std::map<std::string, std::string> account_tokens; |
| 126 android_id, | 128 account_tokens[kEmailAddress] = kTokenValue; |
| 127 security_token, | 129 |
| 128 kSettingsDigest, | 130 CheckinRequest::RequestInfo request_info(android_id, |
| 129 chrome_build_proto_); | 131 security_token, |
| 132 account_tokens, |
| 133 kSettingsDigest, |
| 134 chrome_build_proto_); |
| 130 // Then create a request with that protobuf and specified android_id, | 135 // Then create a request with that protobuf and specified android_id, |
| 131 // security_token. | 136 // security_token. |
| 132 request_.reset(new CheckinRequest( | 137 request_.reset(new CheckinRequest( |
| 133 GURL(kCheckinURL), | 138 GURL(kCheckinURL), |
| 134 request_info, | 139 request_info, |
| 135 kDefaultBackoffPolicy, | 140 kDefaultBackoffPolicy, |
| 136 base::Bind(&CheckinRequestTest::FetcherCallback, base::Unretained(this)), | 141 base::Bind(&CheckinRequestTest::FetcherCallback, base::Unretained(this)), |
| 137 url_request_context_getter_.get(), | 142 url_request_context_getter_.get(), |
| 138 &recorder_)); | 143 &recorder_)); |
| 139 | 144 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 checkin_proto::AndroidCheckinRequest request_proto; | 197 checkin_proto::AndroidCheckinRequest request_proto; |
| 193 request_proto.ParseFromString(fetcher->upload_data()); | 198 request_proto.ParseFromString(fetcher->upload_data()); |
| 194 EXPECT_EQ(kAndroidId, static_cast<uint64>(request_proto.id())); | 199 EXPECT_EQ(kAndroidId, static_cast<uint64>(request_proto.id())); |
| 195 EXPECT_EQ(kSecurityToken, request_proto.security_token()); | 200 EXPECT_EQ(kSecurityToken, request_proto.security_token()); |
| 196 EXPECT_EQ(chrome_build_proto_.platform(), | 201 EXPECT_EQ(chrome_build_proto_.platform(), |
| 197 request_proto.checkin().chrome_build().platform()); | 202 request_proto.checkin().chrome_build().platform()); |
| 198 EXPECT_EQ(chrome_build_proto_.chrome_version(), | 203 EXPECT_EQ(chrome_build_proto_.chrome_version(), |
| 199 request_proto.checkin().chrome_build().chrome_version()); | 204 request_proto.checkin().chrome_build().chrome_version()); |
| 200 EXPECT_EQ(chrome_build_proto_.channel(), | 205 EXPECT_EQ(chrome_build_proto_.channel(), |
| 201 request_proto.checkin().chrome_build().channel()); | 206 request_proto.checkin().chrome_build().channel()); |
| 207 EXPECT_EQ(2, request_proto.account_cookie_size()); |
| 208 EXPECT_EQ(kEmailAddress, request_proto.account_cookie(0)); |
| 209 EXPECT_EQ(kTokenValue, request_proto.account_cookie(1)); |
| 202 | 210 |
| 203 #if defined(CHROME_OS) | 211 #if defined(CHROME_OS) |
| 204 EXPECT_EQ(checkin_proto::DEVICE_CHROME_OS, request_proto.checkin().type()); | 212 EXPECT_EQ(checkin_proto::DEVICE_CHROME_OS, request_proto.checkin().type()); |
| 205 #else | 213 #else |
| 206 EXPECT_EQ(checkin_proto::DEVICE_CHROME_BROWSER, | 214 EXPECT_EQ(checkin_proto::DEVICE_CHROME_BROWSER, |
| 207 request_proto.checkin().type()); | 215 request_proto.checkin().type()); |
| 208 #endif | 216 #endif |
| 209 | 217 |
| 210 EXPECT_EQ(kSettingsDigest, request_proto.digest()); | 218 EXPECT_EQ(kSettingsDigest, request_proto.digest()); |
| 211 } | 219 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 | 379 |
| 372 SetResponse(VALID_RESPONSE); | 380 SetResponse(VALID_RESPONSE); |
| 373 CompleteFetch(); | 381 CompleteFetch(); |
| 374 | 382 |
| 375 EXPECT_TRUE(callback_called_); | 383 EXPECT_TRUE(callback_called_); |
| 376 EXPECT_EQ(kAndroidId, android_id_); | 384 EXPECT_EQ(kAndroidId, android_id_); |
| 377 EXPECT_EQ(kSecurityToken, security_token_); | 385 EXPECT_EQ(kSecurityToken, security_token_); |
| 378 } | 386 } |
| 379 | 387 |
| 380 } // namespace gcm | 388 } // namespace gcm |
| OLD | NEW |