Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Side by Side Diff: components/gcm_driver/gcm_client_impl_unittest.cc

Issue 327263003: Fix the DCHECK failure when starting and stopping GCMClient immediately (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address feedback Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « components/gcm_driver/gcm_client_impl.cc ('k') | google_apis/gcm/engine/gcm_store_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 class GCMClientImplTest : public testing::Test, 212 class GCMClientImplTest : public testing::Test,
213 public GCMClient::Delegate { 213 public GCMClient::Delegate {
214 public: 214 public:
215 GCMClientImplTest(); 215 GCMClientImplTest();
216 virtual ~GCMClientImplTest(); 216 virtual ~GCMClientImplTest();
217 217
218 virtual void SetUp() OVERRIDE; 218 virtual void SetUp() OVERRIDE;
219 219
220 void BuildGCMClient(base::TimeDelta clock_step); 220 void BuildGCMClient(base::TimeDelta clock_step);
221 void InitializeGCMClient(); 221 void InitializeGCMClient();
222 void StartGCMClient();
222 void ReceiveMessageFromMCS(const MCSMessage& message); 223 void ReceiveMessageFromMCS(const MCSMessage& message);
223 void CompleteCheckin(uint64 android_id, 224 void CompleteCheckin(uint64 android_id,
224 uint64 security_token, 225 uint64 security_token,
225 const std::string& digest, 226 const std::string& digest,
226 const std::map<std::string, std::string>& settings); 227 const std::map<std::string, std::string>& settings);
227 void CompleteRegistration(const std::string& registration_id); 228 void CompleteRegistration(const std::string& registration_id);
228 void CompleteUnregistration(const std::string& app_id); 229 void CompleteUnregistration(const std::string& app_id);
229 230
230 bool ExistsRegistration(const std::string& app_id) const; 231 bool ExistsRegistration(const std::string& app_id) const;
231 void AddRegistration(const std::string& app_id, 232 void AddRegistration(const std::string& app_id,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 } 327 }
327 328
328 GCMClientImplTest::~GCMClientImplTest() {} 329 GCMClientImplTest::~GCMClientImplTest() {}
329 330
330 void GCMClientImplTest::SetUp() { 331 void GCMClientImplTest::SetUp() {
331 testing::Test::SetUp(); 332 testing::Test::SetUp();
332 ASSERT_TRUE(CreateUniqueTempDir()); 333 ASSERT_TRUE(CreateUniqueTempDir());
333 InitializeLoop(); 334 InitializeLoop();
334 BuildGCMClient(base::TimeDelta()); 335 BuildGCMClient(base::TimeDelta());
335 InitializeGCMClient(); 336 InitializeGCMClient();
337 StartGCMClient();
336 CompleteCheckin(kDeviceAndroidId, 338 CompleteCheckin(kDeviceAndroidId,
337 kDeviceSecurityToken, 339 kDeviceSecurityToken,
338 std::string(), 340 std::string(),
339 std::map<std::string, std::string>()); 341 std::map<std::string, std::string>());
340 } 342 }
341 343
342 void GCMClientImplTest::PumpLoop() { 344 void GCMClientImplTest::PumpLoop() {
343 run_loop_->Run(); 345 run_loop_->Run();
344 run_loop_.reset(new base::RunLoop()); 346 run_loop_.reset(new base::RunLoop());
345 } 347 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 447
446 // Actual initialization. 448 // Actual initialization.
447 GCMClient::ChromeBuildInfo chrome_build_info; 449 GCMClient::ChromeBuildInfo chrome_build_info;
448 gcm_client_->Initialize(chrome_build_info, 450 gcm_client_->Initialize(chrome_build_info,
449 temp_directory_.path(), 451 temp_directory_.path(),
450 std::vector<std::string>(), 452 std::vector<std::string>(),
451 message_loop_.message_loop_proxy(), 453 message_loop_.message_loop_proxy(),
452 url_request_context_getter_, 454 url_request_context_getter_,
453 make_scoped_ptr<Encryptor>(new FakeEncryptor), 455 make_scoped_ptr<Encryptor>(new FakeEncryptor),
454 this); 456 this);
457 }
455 458
459 void GCMClientImplTest::StartGCMClient() {
456 // Start loading and check-in. 460 // Start loading and check-in.
457 gcm_client_->Start(); 461 gcm_client_->Start();
458 462
459 PumpLoopUntilIdle(); 463 PumpLoopUntilIdle();
460 } 464 }
461 465
462 void GCMClientImplTest::ReceiveMessageFromMCS(const MCSMessage& message) { 466 void GCMClientImplTest::ReceiveMessageFromMCS(const MCSMessage& message) {
463 gcm_client_->OnMessageReceivedFromMCS(message); 467 gcm_client_->OnMessageReceivedFromMCS(message);
464 } 468 }
465 469
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 EXPECT_TRUE(ExistsRegistration(kAppId)); 553 EXPECT_TRUE(ExistsRegistration(kAppId));
550 554
551 EXPECT_EQ(kAppId, last_app_id()); 555 EXPECT_EQ(kAppId, last_app_id());
552 EXPECT_EQ("reg_id", last_registration_id()); 556 EXPECT_EQ("reg_id", last_registration_id());
553 EXPECT_EQ(GCMClient::SUCCESS, last_result()); 557 EXPECT_EQ(GCMClient::SUCCESS, last_result());
554 EXPECT_EQ(REGISTRATION_COMPLETED, last_event()); 558 EXPECT_EQ(REGISTRATION_COMPLETED, last_event());
555 559
556 // Recreate GCMClient in order to load from the persistent store. 560 // Recreate GCMClient in order to load from the persistent store.
557 BuildGCMClient(base::TimeDelta()); 561 BuildGCMClient(base::TimeDelta());
558 InitializeGCMClient(); 562 InitializeGCMClient();
563 StartGCMClient();
559 564
560 EXPECT_TRUE(ExistsRegistration(kAppId)); 565 EXPECT_TRUE(ExistsRegistration(kAppId));
561 } 566 }
562 567
563 TEST_F(GCMClientImplTest, UnregisterApp) { 568 TEST_F(GCMClientImplTest, UnregisterApp) {
564 EXPECT_FALSE(ExistsRegistration(kAppId)); 569 EXPECT_FALSE(ExistsRegistration(kAppId));
565 570
566 std::vector<std::string> senders; 571 std::vector<std::string> senders;
567 senders.push_back("sender"); 572 senders.push_back("sender");
568 gcm_client()->Register(kAppId, senders); 573 gcm_client()->Register(kAppId, senders);
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 702
698 void GCMClientImplCheckinTest::SetUp() { 703 void GCMClientImplCheckinTest::SetUp() {
699 testing::Test::SetUp(); 704 testing::Test::SetUp();
700 // Creating unique temp directory that will be used by GCMStore shared between 705 // Creating unique temp directory that will be used by GCMStore shared between
701 // GCM Client and G-services settings. 706 // GCM Client and G-services settings.
702 ASSERT_TRUE(CreateUniqueTempDir()); 707 ASSERT_TRUE(CreateUniqueTempDir());
703 InitializeLoop(); 708 InitializeLoop();
704 // Time will be advancing one hour every time it is checked. 709 // Time will be advancing one hour every time it is checked.
705 BuildGCMClient(base::TimeDelta::FromSeconds(kSettingsCheckinInterval)); 710 BuildGCMClient(base::TimeDelta::FromSeconds(kSettingsCheckinInterval));
706 InitializeGCMClient(); 711 InitializeGCMClient();
712 StartGCMClient();
707 } 713 }
708 714
709 TEST_F(GCMClientImplCheckinTest, GServicesSettingsAfterInitialCheckin) { 715 TEST_F(GCMClientImplCheckinTest, GServicesSettingsAfterInitialCheckin) {
710 std::map<std::string, std::string> settings; 716 std::map<std::string, std::string> settings;
711 settings["checkin_interval"] = base::Int64ToString(kSettingsCheckinInterval); 717 settings["checkin_interval"] = base::Int64ToString(kSettingsCheckinInterval);
712 settings["checkin_url"] = "http://alternative.url/checkin"; 718 settings["checkin_url"] = "http://alternative.url/checkin";
713 settings["gcm_hostname"] = "alternative.gcm.host"; 719 settings["gcm_hostname"] = "alternative.gcm.host";
714 settings["gcm_secure_port"] = "7777"; 720 settings["gcm_secure_port"] = "7777";
715 settings["gcm_registration_url"] = "http://alternative.url/registration"; 721 settings["gcm_registration_url"] = "http://alternative.url/registration";
716 CompleteCheckin(kDeviceAndroidId, 722 CompleteCheckin(kDeviceAndroidId,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 settings["gcm_hostname"] = "alternative.gcm.host"; 763 settings["gcm_hostname"] = "alternative.gcm.host";
758 settings["gcm_secure_port"] = "7777"; 764 settings["gcm_secure_port"] = "7777";
759 settings["gcm_registration_url"] = "http://alternative.url/registration"; 765 settings["gcm_registration_url"] = "http://alternative.url/registration";
760 CompleteCheckin(kDeviceAndroidId, 766 CompleteCheckin(kDeviceAndroidId,
761 kDeviceSecurityToken, 767 kDeviceSecurityToken,
762 GServicesSettings::CalculateDigest(settings), 768 GServicesSettings::CalculateDigest(settings),
763 settings); 769 settings);
764 770
765 BuildGCMClient(base::TimeDelta()); 771 BuildGCMClient(base::TimeDelta());
766 InitializeGCMClient(); 772 InitializeGCMClient();
773 StartGCMClient();
767 774
768 EXPECT_EQ(base::TimeDelta::FromSeconds(kSettingsCheckinInterval), 775 EXPECT_EQ(base::TimeDelta::FromSeconds(kSettingsCheckinInterval),
769 gservices_settings().GetCheckinInterval()); 776 gservices_settings().GetCheckinInterval());
770 EXPECT_EQ(GURL("http://alternative.url/checkin"), 777 EXPECT_EQ(GURL("http://alternative.url/checkin"),
771 gservices_settings().GetCheckinURL()); 778 gservices_settings().GetCheckinURL());
772 EXPECT_EQ(GURL("http://alternative.url/registration"), 779 EXPECT_EQ(GURL("http://alternative.url/registration"),
773 gservices_settings().GetRegistrationURL()); 780 gservices_settings().GetRegistrationURL());
774 EXPECT_EQ(GURL("https://alternative.gcm.host:7777"), 781 EXPECT_EQ(GURL("https://alternative.gcm.host:7777"),
775 gservices_settings().GetMCSMainEndpoint()); 782 gservices_settings().GetMCSMainEndpoint());
776 EXPECT_EQ(GURL("https://alternative.gcm.host:443"), 783 EXPECT_EQ(GURL("https://alternative.gcm.host:443"),
777 gservices_settings().GetMCSFallbackEndpoint()); 784 gservices_settings().GetMCSFallbackEndpoint());
778 } 785 }
779 786
787 class GCMClientImplStartAndStopTest : public GCMClientImplTest {
788 public:
789 GCMClientImplStartAndStopTest();
790 virtual ~GCMClientImplStartAndStopTest();
791
792 virtual void SetUp() OVERRIDE;
793 };
794
795 GCMClientImplStartAndStopTest::GCMClientImplStartAndStopTest() {
796 }
797
798 GCMClientImplStartAndStopTest::~GCMClientImplStartAndStopTest() {
799 }
800
801 void GCMClientImplStartAndStopTest::SetUp() {
802 testing::Test::SetUp();
803 ASSERT_TRUE(CreateUniqueTempDir());
804 InitializeLoop();
805 BuildGCMClient(base::TimeDelta());
806 InitializeGCMClient();
807 }
808
809 TEST_F(GCMClientImplStartAndStopTest, StartStopAndRestart) {
810 // Start the GCM and wait until it is ready.
811 gcm_client()->Start();
812 PumpLoopUntilIdle();
813
814 // Stop the GCM.
815 gcm_client()->Stop();
816 PumpLoopUntilIdle();
817
818 // Restart the GCM.
819 gcm_client()->Start();
820 PumpLoopUntilIdle();
821 }
822
823 TEST_F(GCMClientImplStartAndStopTest, StartAndStopImmediately) {
824 // Start the GCM and then stop it immediately.
825 gcm_client()->Start();
826 gcm_client()->Stop();
827
828 PumpLoopUntilIdle();
829 }
830
831 TEST_F(GCMClientImplStartAndStopTest, StartStopAndRestartImmediately) {
832 // Start the GCM and then stop and restart it immediately.
833 gcm_client()->Start();
834 gcm_client()->Stop();
835 gcm_client()->Start();
836
837 PumpLoopUntilIdle();
838 }
839
780 } // namespace gcm 840 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_client_impl.cc ('k') | google_apis/gcm/engine/gcm_store_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698