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

Side by Side Diff: google_apis/gcm/gcm_client_impl_unittest.cc

Issue 288433002: G-services settings v3 implementation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing CR feedback Created 6 years, 7 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 | « google_apis/gcm/gcm_client_impl.cc ('k') | no next file » | 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 "google_apis/gcm/gcm_client_impl.h" 5 #include "google_apis/gcm/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 24 matching lines...) Expand all
35 REGISTRATION_COMPLETED, 35 REGISTRATION_COMPLETED,
36 UNREGISTRATION_COMPLETED, 36 UNREGISTRATION_COMPLETED,
37 MESSAGE_SEND_ERROR, 37 MESSAGE_SEND_ERROR,
38 MESSAGE_RECEIVED, 38 MESSAGE_RECEIVED,
39 MESSAGES_DELETED, 39 MESSAGES_DELETED,
40 }; 40 };
41 41
42 const uint64 kDeviceAndroidId = 54321; 42 const uint64 kDeviceAndroidId = 54321;
43 const uint64 kDeviceSecurityToken = 12345; 43 const uint64 kDeviceSecurityToken = 12345;
44 const int64 kSettingsCheckinInterval = 16 * 60 * 60; 44 const int64 kSettingsCheckinInterval = 16 * 60 * 60;
45 const char kSettingsDefaultDigest[] = "default_digest";
46 const char kAppId[] = "app_id"; 45 const char kAppId[] = "app_id";
47 const char kSender[] = "project_id"; 46 const char kSender[] = "project_id";
48 const char kSender2[] = "project_id2"; 47 const char kSender2[] = "project_id2";
49 const char kSender3[] = "project_id3"; 48 const char kSender3[] = "project_id3";
50 const char kRegistrationResponsePrefix[] = "token="; 49 const char kRegistrationResponsePrefix[] = "token=";
51 const char kUnregistrationResponsePrefix[] = "deleted="; 50 const char kUnregistrationResponsePrefix[] = "deleted=";
52 51
53 // Helper for building arbitrary data messages. 52 // Helper for building arbitrary data messages.
54 MCSMessage BuildDownstreamMessage( 53 MCSMessage BuildDownstreamMessage(
55 const std::string& project_id, 54 const std::string& project_id,
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 if (!digest.empty()) { 381 if (!digest.empty()) {
383 response.set_digest(digest); 382 response.set_digest(digest);
384 for (std::map<std::string, std::string>::const_iterator it = 383 for (std::map<std::string, std::string>::const_iterator it =
385 settings.begin(); 384 settings.begin();
386 it != settings.end(); 385 it != settings.end();
387 ++it) { 386 ++it) {
388 checkin_proto::GservicesSetting* setting = response.add_setting(); 387 checkin_proto::GservicesSetting* setting = response.add_setting();
389 setting->set_name(it->first); 388 setting->set_name(it->first);
390 setting->set_value(it->second); 389 setting->set_value(it->second);
391 } 390 }
391 response.set_settings_diff(false);
392 } 392 }
393 393
394 std::string response_string; 394 std::string response_string;
395 response.SerializeToString(&response_string); 395 response.SerializeToString(&response_string);
396 396
397 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 397 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
398 ASSERT_TRUE(fetcher); 398 ASSERT_TRUE(fetcher);
399 fetcher->set_response_code(net::HTTP_OK); 399 fetcher->set_response_code(net::HTTP_OK);
400 fetcher->SetResponseString(response_string); 400 fetcher->SetResponseString(response_string);
401 fetcher->delegate()->OnURLFetchComplete(fetcher); 401 fetcher->delegate()->OnURLFetchComplete(fetcher);
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 EXPECT_EQ("value", 680 EXPECT_EQ("value",
681 mcs_client()->last_data_message_stanza().app_data(0).value()); 681 mcs_client()->last_data_message_stanza().app_data(0).value());
682 } 682 }
683 683
684 class GCMClientImplCheckinTest : public GCMClientImplTest { 684 class GCMClientImplCheckinTest : public GCMClientImplTest {
685 public: 685 public:
686 GCMClientImplCheckinTest(); 686 GCMClientImplCheckinTest();
687 virtual ~GCMClientImplCheckinTest(); 687 virtual ~GCMClientImplCheckinTest();
688 688
689 virtual void SetUp() OVERRIDE; 689 virtual void SetUp() OVERRIDE;
690
691 std::map<std::string, std::string> GenerateSettings(int64 checkin_interval);
692 }; 690 };
693 691
694 GCMClientImplCheckinTest::GCMClientImplCheckinTest() { 692 GCMClientImplCheckinTest::GCMClientImplCheckinTest() {
695 } 693 }
696 694
697 GCMClientImplCheckinTest::~GCMClientImplCheckinTest() { 695 GCMClientImplCheckinTest::~GCMClientImplCheckinTest() {
698 } 696 }
699 697
700 void GCMClientImplCheckinTest::SetUp() { 698 void GCMClientImplCheckinTest::SetUp() {
701 testing::Test::SetUp(); 699 testing::Test::SetUp();
702 // Creating unique temp directory that will be used by GCMStore shared between 700 // Creating unique temp directory that will be used by GCMStore shared between
703 // GCM Client and G-services settings. 701 // GCM Client and G-services settings.
704 ASSERT_TRUE(CreateUniqueTempDir()); 702 ASSERT_TRUE(CreateUniqueTempDir());
705 InitializeLoop(); 703 InitializeLoop();
706 // Time will be advancing one hour every time it is checked. 704 // Time will be advancing one hour every time it is checked.
707 BuildGCMClient(base::TimeDelta::FromSeconds(kSettingsCheckinInterval)); 705 BuildGCMClient(base::TimeDelta::FromSeconds(kSettingsCheckinInterval));
708 InitializeGCMClient(); 706 InitializeGCMClient();
709 } 707 }
710 708
711 TEST_F(GCMClientImplCheckinTest, GServicesSettingsAfterInitialCheckin) { 709 TEST_F(GCMClientImplCheckinTest, GServicesSettingsAfterInitialCheckin) {
712 std::map<std::string, std::string> settings; 710 std::map<std::string, std::string> settings;
713 settings["checkin_interval"] = base::Int64ToString(kSettingsCheckinInterval); 711 settings["checkin_interval"] = base::Int64ToString(kSettingsCheckinInterval);
714 settings["checkin_url"] = "http://alternative.url/checkin"; 712 settings["checkin_url"] = "http://alternative.url/checkin";
715 settings["gcm_hostname"] = "alternative.gcm.host"; 713 settings["gcm_hostname"] = "alternative.gcm.host";
716 settings["gcm_secure_port"] = "7777"; 714 settings["gcm_secure_port"] = "7777";
717 settings["gcm_registration_url"] = "http://alternative.url/registration"; 715 settings["gcm_registration_url"] = "http://alternative.url/registration";
718 CompleteCheckin( 716 CompleteCheckin(kDeviceAndroidId,
719 kDeviceAndroidId, kDeviceSecurityToken, kSettingsDefaultDigest, settings); 717 kDeviceSecurityToken,
718 GServicesSettings::CalculateDigest(settings),
719 settings);
720 EXPECT_EQ(base::TimeDelta::FromSeconds(kSettingsCheckinInterval), 720 EXPECT_EQ(base::TimeDelta::FromSeconds(kSettingsCheckinInterval),
721 gservices_settings().checkin_interval()); 721 gservices_settings().GetCheckinInterval());
722 EXPECT_EQ(GURL("http://alternative.url/checkin"), 722 EXPECT_EQ(GURL("http://alternative.url/checkin"),
723 gservices_settings().checkin_url()); 723 gservices_settings().GetCheckinURL());
724 EXPECT_EQ(GURL("http://alternative.url/registration"), 724 EXPECT_EQ(GURL("http://alternative.url/registration"),
725 gservices_settings().registration_url()); 725 gservices_settings().GetRegistrationURL());
726 EXPECT_EQ(GURL("https://alternative.gcm.host:7777"), 726 EXPECT_EQ(GURL("https://alternative.gcm.host:7777"),
727 gservices_settings().mcs_main_endpoint()); 727 gservices_settings().GetMCSMainEndpoint());
728 EXPECT_EQ(GURL("https://alternative.gcm.host:443"), 728 EXPECT_EQ(GURL("https://alternative.gcm.host:443"),
729 gservices_settings().mcs_fallback_endpoint()); 729 gservices_settings().GetMCSFallbackEndpoint());
730 } 730 }
731 731
732 // This test only checks that periodic checkin happens. 732 // This test only checks that periodic checkin happens.
733 TEST_F(GCMClientImplCheckinTest, PeriodicCheckin) { 733 TEST_F(GCMClientImplCheckinTest, PeriodicCheckin) {
734 std::map<std::string, std::string> settings; 734 std::map<std::string, std::string> settings;
735 settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval); 735 settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval);
736 settings["checkin_url"] = "http://alternative.url/checkin"; 736 settings["checkin_url"] = "http://alternative.url/checkin";
737 settings["gcm_hostname"] = "alternative.gcm.host"; 737 settings["gcm_hostname"] = "alternative.gcm.host";
738 settings["gcm_secure_port"] = "7777"; 738 settings["gcm_secure_port"] = "7777";
739 settings["gcm_registration_url"] = "http://alternative.url/registration"; 739 settings["gcm_registration_url"] = "http://alternative.url/registration";
740 CompleteCheckin( 740 CompleteCheckin(kDeviceAndroidId,
741 kDeviceAndroidId, kDeviceSecurityToken, kSettingsDefaultDigest, settings); 741 kDeviceSecurityToken,
742 GServicesSettings::CalculateDigest(settings),
743 settings);
742 EXPECT_EQ(2, clock()->call_count()); 744 EXPECT_EQ(2, clock()->call_count());
743 745
744 PumpLoopUntilIdle(); 746 PumpLoopUntilIdle();
745 CompleteCheckin( 747 CompleteCheckin(kDeviceAndroidId,
746 kDeviceAndroidId, kDeviceSecurityToken, kSettingsDefaultDigest, settings); 748 kDeviceSecurityToken,
749 GServicesSettings::CalculateDigest(settings),
750 settings);
747 } 751 }
748 752
749 TEST_F(GCMClientImplCheckinTest, LoadGSettingsFromStore) { 753 TEST_F(GCMClientImplCheckinTest, LoadGSettingsFromStore) {
750 std::map<std::string, std::string> settings; 754 std::map<std::string, std::string> settings;
751 settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval); 755 settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval);
752 settings["checkin_url"] = "http://alternative.url/checkin"; 756 settings["checkin_url"] = "http://alternative.url/checkin";
753 settings["gcm_hostname"] = "alternative.gcm.host"; 757 settings["gcm_hostname"] = "alternative.gcm.host";
754 settings["gcm_secure_port"] = "7777"; 758 settings["gcm_secure_port"] = "7777";
755 settings["gcm_registration_url"] = "http://alternative.url/registration"; 759 settings["gcm_registration_url"] = "http://alternative.url/registration";
756 CompleteCheckin( 760 CompleteCheckin(kDeviceAndroidId,
757 kDeviceAndroidId, kDeviceSecurityToken, kSettingsDefaultDigest, settings); 761 kDeviceSecurityToken,
762 GServicesSettings::CalculateDigest(settings),
763 settings);
758 764
759 BuildGCMClient(base::TimeDelta()); 765 BuildGCMClient(base::TimeDelta());
760 InitializeGCMClient(); 766 InitializeGCMClient();
761 767
762 EXPECT_EQ(base::TimeDelta::FromSeconds(kSettingsCheckinInterval), 768 EXPECT_EQ(base::TimeDelta::FromSeconds(kSettingsCheckinInterval),
763 gservices_settings().checkin_interval()); 769 gservices_settings().GetCheckinInterval());
764 EXPECT_EQ(GURL("http://alternative.url/checkin"), 770 EXPECT_EQ(GURL("http://alternative.url/checkin"),
765 gservices_settings().checkin_url()); 771 gservices_settings().GetCheckinURL());
766 EXPECT_EQ(GURL("http://alternative.url/registration"), 772 EXPECT_EQ(GURL("http://alternative.url/registration"),
767 gservices_settings().registration_url()); 773 gservices_settings().GetRegistrationURL());
768 EXPECT_EQ(GURL("https://alternative.gcm.host:7777"), 774 EXPECT_EQ(GURL("https://alternative.gcm.host:7777"),
769 gservices_settings().mcs_main_endpoint()); 775 gservices_settings().GetMCSMainEndpoint());
770 EXPECT_EQ(GURL("https://alternative.gcm.host:443"), 776 EXPECT_EQ(GURL("https://alternative.gcm.host:443"),
771 gservices_settings().mcs_fallback_endpoint()); 777 gservices_settings().GetMCSFallbackEndpoint());
772 } 778 }
773 779
774 } // namespace gcm 780 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/gcm_client_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698