Chromium Code Reviews| 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 "components/gcm_driver/gcm_client_impl.h" | 5 #include "components/gcm_driver/gcm_client_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <initializer_list> | 9 #include <initializer_list> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 void InitializeGCMClient(); | 273 void InitializeGCMClient(); |
| 274 void StartGCMClient(); | 274 void StartGCMClient(); |
| 275 void Register(const std::string& app_id, | 275 void Register(const std::string& app_id, |
| 276 const std::vector<std::string>& senders); | 276 const std::vector<std::string>& senders); |
| 277 void Unregister(const std::string& app_id); | 277 void Unregister(const std::string& app_id); |
| 278 void ReceiveMessageFromMCS(const MCSMessage& message); | 278 void ReceiveMessageFromMCS(const MCSMessage& message); |
| 279 void ReceiveOnMessageSentToMCS( | 279 void ReceiveOnMessageSentToMCS( |
| 280 const std::string& app_id, | 280 const std::string& app_id, |
| 281 const std::string& message_id, | 281 const std::string& message_id, |
| 282 const MCSClient::MessageSendStatus status); | 282 const MCSClient::MessageSendStatus status); |
| 283 void FailCheckin(net::HttpStatusCode response_code); | |
| 283 void CompleteCheckin(uint64_t android_id, | 284 void CompleteCheckin(uint64_t android_id, |
| 284 uint64_t security_token, | 285 uint64_t security_token, |
| 285 const std::string& digest, | 286 const std::string& digest, |
| 286 const std::map<std::string, std::string>& settings); | 287 const std::map<std::string, std::string>& settings); |
| 288 void CompleteCheckinImpl(uint64_t android_id, | |
| 289 uint64_t security_token, | |
| 290 const std::string& digest, | |
| 291 const std::map<std::string, std::string>& settings, | |
| 292 net::HttpStatusCode response_code); | |
| 287 void CompleteRegistration(const std::string& registration_id); | 293 void CompleteRegistration(const std::string& registration_id); |
| 288 void CompleteUnregistration(const std::string& app_id); | 294 void CompleteUnregistration(const std::string& app_id); |
| 289 void VerifyPendingRequestFetcherDeleted(); | 295 void VerifyPendingRequestFetcherDeleted(); |
| 290 | 296 |
| 291 bool ExistsRegistration(const std::string& app_id) const; | 297 bool ExistsRegistration(const std::string& app_id) const; |
| 292 void AddRegistration(const std::string& app_id, | 298 void AddRegistration(const std::string& app_id, |
| 293 const std::vector<std::string>& sender_ids, | 299 const std::vector<std::string>& sender_ids, |
| 294 const std::string& registration_id); | 300 const std::string& registration_id); |
| 295 | 301 |
| 296 // GCMClient::Delegate overrides (for verification). | 302 // GCMClient::Delegate overrides (for verification). |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 | 456 |
| 451 bool GCMClientImplTest::CreateUniqueTempDir() { | 457 bool GCMClientImplTest::CreateUniqueTempDir() { |
| 452 return temp_directory_.CreateUniqueTempDir(); | 458 return temp_directory_.CreateUniqueTempDir(); |
| 453 } | 459 } |
| 454 | 460 |
| 455 void GCMClientImplTest::BuildGCMClient(base::TimeDelta clock_step) { | 461 void GCMClientImplTest::BuildGCMClient(base::TimeDelta clock_step) { |
| 456 gcm_client_.reset(new GCMClientImpl(base::WrapUnique<GCMInternalsBuilder>( | 462 gcm_client_.reset(new GCMClientImpl(base::WrapUnique<GCMInternalsBuilder>( |
| 457 new FakeGCMInternalsBuilder(clock_step)))); | 463 new FakeGCMInternalsBuilder(clock_step)))); |
| 458 } | 464 } |
| 459 | 465 |
| 466 void GCMClientImplTest::FailCheckin(net::HttpStatusCode response_code) { | |
| 467 std::map<std::string, std::string> settings; | |
| 468 CompleteCheckinImpl(0, 0, GServicesSettings::CalculateDigest(settings), | |
| 469 settings, response_code); | |
| 470 } | |
| 471 | |
| 460 void GCMClientImplTest::CompleteCheckin( | 472 void GCMClientImplTest::CompleteCheckin( |
| 461 uint64_t android_id, | 473 uint64_t android_id, |
| 462 uint64_t security_token, | 474 uint64_t security_token, |
| 463 const std::string& digest, | 475 const std::string& digest, |
| 464 const std::map<std::string, std::string>& settings) { | 476 const std::map<std::string, std::string>& settings) { |
| 477 CompleteCheckinImpl(android_id, security_token, digest, settings, | |
| 478 net::HTTP_OK); | |
| 479 } | |
| 480 | |
| 481 void GCMClientImplTest::CompleteCheckinImpl( | |
| 482 uint64_t android_id, | |
| 483 uint64_t security_token, | |
| 484 const std::string& digest, | |
| 485 const std::map<std::string, std::string>& settings, | |
| 486 net::HttpStatusCode response_code) { | |
| 465 checkin_proto::AndroidCheckinResponse response; | 487 checkin_proto::AndroidCheckinResponse response; |
| 466 response.set_stats_ok(true); | 488 response.set_stats_ok(true); |
| 467 response.set_android_id(android_id); | 489 response.set_android_id(android_id); |
| 468 response.set_security_token(security_token); | 490 response.set_security_token(security_token); |
| 469 | 491 |
| 470 // For testing G-services settings. | 492 // For testing G-services settings. |
| 471 if (!digest.empty()) { | 493 if (!digest.empty()) { |
| 472 response.set_digest(digest); | 494 response.set_digest(digest); |
| 473 for (std::map<std::string, std::string>::const_iterator it = | 495 for (std::map<std::string, std::string>::const_iterator it = |
| 474 settings.begin(); | 496 settings.begin(); |
| 475 it != settings.end(); | 497 it != settings.end(); |
| 476 ++it) { | 498 ++it) { |
| 477 checkin_proto::GservicesSetting* setting = response.add_setting(); | 499 checkin_proto::GservicesSetting* setting = response.add_setting(); |
| 478 setting->set_name(it->first); | 500 setting->set_name(it->first); |
| 479 setting->set_value(it->second); | 501 setting->set_value(it->second); |
| 480 } | 502 } |
| 481 response.set_settings_diff(false); | 503 response.set_settings_diff(false); |
| 482 } | 504 } |
| 483 | 505 |
| 484 std::string response_string; | 506 std::string response_string; |
| 485 response.SerializeToString(&response_string); | 507 response.SerializeToString(&response_string); |
| 486 | 508 |
| 487 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 509 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
| 488 ASSERT_TRUE(fetcher); | 510 ASSERT_TRUE(fetcher); |
| 489 fetcher->set_response_code(net::HTTP_OK); | 511 fetcher->set_response_code(response_code); |
| 490 fetcher->SetResponseString(response_string); | 512 fetcher->SetResponseString(response_string); |
| 491 fetcher->delegate()->OnURLFetchComplete(fetcher); | 513 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 492 // Give a chance for GCMStoreImpl::Backend to finish persisting data. | 514 // Give a chance for GCMStoreImpl::Backend to finish persisting data. |
| 493 PumpLoopUntilIdle(); | 515 PumpLoopUntilIdle(); |
| 494 } | 516 } |
| 495 | 517 |
| 496 void GCMClientImplTest::CompleteRegistration( | 518 void GCMClientImplTest::CompleteRegistration( |
| 497 const std::string& registration_id) { | 519 const std::string& registration_id) { |
| 498 std::string response(kRegistrationResponsePrefix); | 520 std::string response(kRegistrationResponsePrefix); |
| 499 response.append(registration_id); | 521 response.append(registration_id); |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1207 GServicesSettings::CalculateDigest(settings), settings)); | 1229 GServicesSettings::CalculateDigest(settings), settings)); |
| 1208 | 1230 |
| 1209 accounts.clear(); | 1231 accounts.clear(); |
| 1210 accounts.insert("test_user2@gmail.com"); | 1232 accounts.insert("test_user2@gmail.com"); |
| 1211 EXPECT_EQ(accounts, device_checkin_info().last_checkin_accounts); | 1233 EXPECT_EQ(accounts, device_checkin_info().last_checkin_accounts); |
| 1212 EXPECT_TRUE(device_checkin_info().accounts_set); | 1234 EXPECT_TRUE(device_checkin_info().accounts_set); |
| 1213 EXPECT_EQ(MakeEmailToTokenMap(account_tokens), | 1235 EXPECT_EQ(MakeEmailToTokenMap(account_tokens), |
| 1214 device_checkin_info().account_tokens); | 1236 device_checkin_info().account_tokens); |
| 1215 } | 1237 } |
| 1216 | 1238 |
| 1239 TEST_F(GCMClientImplCheckinTest, ResetStoreWhenCheckinRejected) { | |
| 1240 std::map<std::string, std::string> settings; | |
| 1241 ASSERT_NO_FATAL_FAILURE(FailCheckin(net::HTTP_UNAUTHORIZED)); | |
| 1242 PumpLoopUntilIdle(); | |
| 1243 | |
| 1244 // Store should have been destroyed. Restart client and verify the initial | |
| 1245 // checkin response is persisted. | |
|
Peter Beverloo
2016/10/28 15:52:30
fwiw, I've found using the base::HistogramTester a
Nicolas Zea
2016/11/01 00:18:16
In this scenario there aren't any new histograms b
Peter Beverloo
2016/11/01 15:19:14
Resetting the store would record to the GCM.ResetS
| |
| 1246 BuildGCMClient(base::TimeDelta()); | |
| 1247 InitializeGCMClient(); | |
| 1248 StartGCMClient(); | |
| 1249 ASSERT_NO_FATAL_FAILURE( | |
| 1250 CompleteCheckin(kDeviceAndroidId2, kDeviceSecurityToken2, | |
| 1251 GServicesSettings::CalculateDigest(settings), settings)); | |
| 1252 | |
| 1253 EXPECT_EQ(LOADING_COMPLETED, last_event()); | |
| 1254 EXPECT_EQ(kDeviceAndroidId2, mcs_client()->last_android_id()); | |
| 1255 EXPECT_EQ(kDeviceSecurityToken2, mcs_client()->last_security_token()); | |
| 1256 } | |
| 1257 | |
| 1217 class GCMClientImplStartAndStopTest : public GCMClientImplTest { | 1258 class GCMClientImplStartAndStopTest : public GCMClientImplTest { |
| 1218 public: | 1259 public: |
| 1219 GCMClientImplStartAndStopTest(); | 1260 GCMClientImplStartAndStopTest(); |
| 1220 ~GCMClientImplStartAndStopTest() override; | 1261 ~GCMClientImplStartAndStopTest() override; |
| 1221 | 1262 |
| 1222 void SetUp() override; | 1263 void SetUp() override; |
| 1223 | 1264 |
| 1224 void DefaultCompleteCheckin(); | 1265 void DefaultCompleteCheckin(); |
| 1225 }; | 1266 }; |
| 1226 | 1267 |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1873 ReceiveMessageFromMCS(message); | 1914 ReceiveMessageFromMCS(message); |
| 1874 | 1915 |
| 1875 EXPECT_EQ(MESSAGE_RECEIVED, last_event()); | 1916 EXPECT_EQ(MESSAGE_RECEIVED, last_event()); |
| 1876 EXPECT_EQ(kExtensionAppId, last_app_id()); | 1917 EXPECT_EQ(kExtensionAppId, last_app_id()); |
| 1877 EXPECT_EQ(expected_data.size(), last_message().data.size()); | 1918 EXPECT_EQ(expected_data.size(), last_message().data.size()); |
| 1878 EXPECT_EQ(expected_data, last_message().data); | 1919 EXPECT_EQ(expected_data, last_message().data); |
| 1879 EXPECT_EQ(kSender, last_message().sender_id); | 1920 EXPECT_EQ(kSender, last_message().sender_id); |
| 1880 } | 1921 } |
| 1881 | 1922 |
| 1882 } // namespace gcm | 1923 } // namespace gcm |
| OLD | NEW |