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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | |
9 #include "base/files/file_util.h" | |
8 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
11 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
12 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
13 #include "base/time/clock.h" | 15 #include "base/time/clock.h" |
14 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
15 #include "google_apis/gcm/base/fake_encryptor.h" | 17 #include "google_apis/gcm/base/fake_encryptor.h" |
16 #include "google_apis/gcm/base/mcs_message.h" | 18 #include "google_apis/gcm/base/mcs_message.h" |
17 #include "google_apis/gcm/base/mcs_util.h" | 19 #include "google_apis/gcm/base/mcs_util.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
37 REGISTRATION_COMPLETED, | 39 REGISTRATION_COMPLETED, |
38 UNREGISTRATION_COMPLETED, | 40 UNREGISTRATION_COMPLETED, |
39 MESSAGE_SEND_ERROR, | 41 MESSAGE_SEND_ERROR, |
40 MESSAGE_SEND_ACK, | 42 MESSAGE_SEND_ACK, |
41 MESSAGE_RECEIVED, | 43 MESSAGE_RECEIVED, |
42 MESSAGES_DELETED, | 44 MESSAGES_DELETED, |
43 }; | 45 }; |
44 | 46 |
45 const uint64 kDeviceAndroidId = 54321; | 47 const uint64 kDeviceAndroidId = 54321; |
46 const uint64 kDeviceSecurityToken = 12345; | 48 const uint64 kDeviceSecurityToken = 12345; |
49 const uint64 kDeviceAndroidId2 = 11111; | |
50 const uint64 kDeviceSecurityToken2 = 2222; | |
47 const int64 kSettingsCheckinInterval = 16 * 60 * 60; | 51 const int64 kSettingsCheckinInterval = 16 * 60 * 60; |
48 const char kAppId[] = "app_id"; | 52 const char kAppId[] = "app_id"; |
49 const char kSender[] = "project_id"; | 53 const char kSender[] = "project_id"; |
50 const char kSender2[] = "project_id2"; | 54 const char kSender2[] = "project_id2"; |
51 const char kSender3[] = "project_id3"; | 55 const char kSender3[] = "project_id3"; |
52 const char kRegistrationResponsePrefix[] = "token="; | 56 const char kRegistrationResponsePrefix[] = "token="; |
53 const char kUnregistrationResponsePrefix[] = "deleted="; | 57 const char kUnregistrationResponsePrefix[] = "deleted="; |
54 | 58 |
55 // Helper for building arbitrary data messages. | 59 // Helper for building arbitrary data messages. |
56 MCSMessage BuildDownstreamMessage( | 60 MCSMessage BuildDownstreamMessage( |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 return last_token_fetch_time_; | 331 return last_token_fetch_time_; |
328 } | 332 } |
329 const std::vector<AccountMapping>& last_account_mappings() { | 333 const std::vector<AccountMapping>& last_account_mappings() { |
330 return last_account_mappings_; | 334 return last_account_mappings_; |
331 } | 335 } |
332 | 336 |
333 const GServicesSettings& gservices_settings() const { | 337 const GServicesSettings& gservices_settings() const { |
334 return gcm_client_->gservices_settings_; | 338 return gcm_client_->gservices_settings_; |
335 } | 339 } |
336 | 340 |
341 const base::FilePath& temp_directory_path() const { | |
342 return temp_directory_.path(); | |
343 } | |
344 | |
337 int64 CurrentTime(); | 345 int64 CurrentTime(); |
338 | 346 |
339 // Tooling. | 347 // Tooling. |
340 void PumpLoop(); | 348 void PumpLoop(); |
341 void PumpLoopUntilIdle(); | 349 void PumpLoopUntilIdle(); |
342 void QuitLoop(); | 350 void QuitLoop(); |
343 void InitializeLoop(); | 351 void InitializeLoop(); |
344 bool CreateUniqueTempDir(); | 352 bool CreateUniqueTempDir(); |
345 AutoAdvancingTestClock* clock() const { | 353 AutoAdvancingTestClock* clock() const { |
346 return reinterpret_cast<AutoAdvancingTestClock*>(gcm_client_->clock_.get()); | 354 return reinterpret_cast<AutoAdvancingTestClock*>(gcm_client_->clock_.get()); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
596 EXPECT_EQ(kDeviceSecurityToken, mcs_client()->last_security_token()); | 604 EXPECT_EQ(kDeviceSecurityToken, mcs_client()->last_security_token()); |
597 | 605 |
598 // Checking freshly loaded CheckinInfo. | 606 // Checking freshly loaded CheckinInfo. |
599 EXPECT_EQ(kDeviceAndroidId, device_checkin_info().android_id); | 607 EXPECT_EQ(kDeviceAndroidId, device_checkin_info().android_id); |
600 EXPECT_EQ(kDeviceSecurityToken, device_checkin_info().secret); | 608 EXPECT_EQ(kDeviceSecurityToken, device_checkin_info().secret); |
601 EXPECT_TRUE(device_checkin_info().last_checkin_accounts.empty()); | 609 EXPECT_TRUE(device_checkin_info().last_checkin_accounts.empty()); |
602 EXPECT_TRUE(device_checkin_info().accounts_set); | 610 EXPECT_TRUE(device_checkin_info().accounts_set); |
603 EXPECT_TRUE(device_checkin_info().account_tokens.empty()); | 611 EXPECT_TRUE(device_checkin_info().account_tokens.empty()); |
604 } | 612 } |
605 | 613 |
614 TEST_F(GCMClientImplTest, LoadingBusted) { | |
615 // Close the GCM store. | |
616 gcm_client()->Stop(); | |
617 PumpLoopUntilIdle(); | |
618 | |
619 // Mess up the store. | |
620 base::FilePath store_file_path = | |
621 temp_directory_path().Append(FILE_PATH_LITERAL("CURRENT")); | |
622 ASSERT_TRUE(base::AppendToFile(store_file_path, "A", 1)); | |
623 | |
624 // Restart GCM client. The store should be resetted and the loading should | |
fgorski
2015/02/10 18:31:31
reset
jianli
2015/02/10 19:45:14
Done.
| |
625 // complete successfully. | |
626 reset_last_event(); | |
627 BuildGCMClient(base::TimeDelta()); | |
628 InitializeGCMClient(); | |
629 StartGCMClient(); | |
630 CompleteCheckin(kDeviceAndroidId2, | |
631 kDeviceSecurityToken2, | |
632 std::string(), | |
633 std::map<std::string, std::string>()); | |
634 | |
635 EXPECT_EQ(LOADING_COMPLETED, last_event()); | |
636 EXPECT_EQ(kDeviceAndroidId2, mcs_client()->last_android_id()); | |
637 EXPECT_EQ(kDeviceSecurityToken2, mcs_client()->last_security_token()); | |
638 } | |
639 | |
606 TEST_F(GCMClientImplTest, RegisterApp) { | 640 TEST_F(GCMClientImplTest, RegisterApp) { |
607 EXPECT_FALSE(ExistsRegistration(kAppId)); | 641 EXPECT_FALSE(ExistsRegistration(kAppId)); |
608 | 642 |
609 std::vector<std::string> senders; | 643 std::vector<std::string> senders; |
610 senders.push_back("sender"); | 644 senders.push_back("sender"); |
611 gcm_client()->Register(kAppId, senders); | 645 gcm_client()->Register(kAppId, senders); |
612 CompleteRegistration("reg_id"); | 646 CompleteRegistration("reg_id"); |
613 | 647 |
614 EXPECT_EQ(REGISTRATION_COMPLETED, last_event()); | 648 EXPECT_EQ(REGISTRATION_COMPLETED, last_event()); |
615 EXPECT_EQ(kAppId, last_app_id()); | 649 EXPECT_EQ(kAppId, last_app_id()); |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1161 ASSERT_EQ(1UL, last_account_mappings().size()); | 1195 ASSERT_EQ(1UL, last_account_mappings().size()); |
1162 const AccountMapping& actual_mapping = last_account_mappings()[0]; | 1196 const AccountMapping& actual_mapping = last_account_mappings()[0]; |
1163 EXPECT_EQ(expected_mapping.account_id, actual_mapping.account_id); | 1197 EXPECT_EQ(expected_mapping.account_id, actual_mapping.account_id); |
1164 EXPECT_EQ(expected_mapping.email, actual_mapping.email); | 1198 EXPECT_EQ(expected_mapping.email, actual_mapping.email); |
1165 EXPECT_EQ(expected_mapping.status, actual_mapping.status); | 1199 EXPECT_EQ(expected_mapping.status, actual_mapping.status); |
1166 EXPECT_EQ(expected_mapping.status_change_timestamp, | 1200 EXPECT_EQ(expected_mapping.status_change_timestamp, |
1167 actual_mapping.status_change_timestamp); | 1201 actual_mapping.status_change_timestamp); |
1168 } | 1202 } |
1169 | 1203 |
1170 } // namespace gcm | 1204 } // namespace gcm |
OLD | NEW |