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 "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 Loading... |
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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 if (!digest.empty()) { | 385 if (!digest.empty()) { |
387 response.set_digest(digest); | 386 response.set_digest(digest); |
388 for (std::map<std::string, std::string>::const_iterator it = | 387 for (std::map<std::string, std::string>::const_iterator it = |
389 settings.begin(); | 388 settings.begin(); |
390 it != settings.end(); | 389 it != settings.end(); |
391 ++it) { | 390 ++it) { |
392 checkin_proto::GservicesSetting* setting = response.add_setting(); | 391 checkin_proto::GservicesSetting* setting = response.add_setting(); |
393 setting->set_name(it->first); | 392 setting->set_name(it->first); |
394 setting->set_value(it->second); | 393 setting->set_value(it->second); |
395 } | 394 } |
| 395 response.set_settings_diff(false); |
396 } | 396 } |
397 | 397 |
398 std::string response_string; | 398 std::string response_string; |
399 response.SerializeToString(&response_string); | 399 response.SerializeToString(&response_string); |
400 | 400 |
401 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); | 401 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); |
402 ASSERT_TRUE(fetcher); | 402 ASSERT_TRUE(fetcher); |
403 fetcher->set_response_code(net::HTTP_OK); | 403 fetcher->set_response_code(net::HTTP_OK); |
404 fetcher->SetResponseString(response_string); | 404 fetcher->SetResponseString(response_string); |
405 fetcher->delegate()->OnURLFetchComplete(fetcher); | 405 fetcher->delegate()->OnURLFetchComplete(fetcher); |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 EXPECT_EQ("value", | 683 EXPECT_EQ("value", |
684 mcs_client()->last_data_message_stanza().app_data(0).value()); | 684 mcs_client()->last_data_message_stanza().app_data(0).value()); |
685 } | 685 } |
686 | 686 |
687 class GCMClientImplCheckinTest : public GCMClientImplTest { | 687 class GCMClientImplCheckinTest : public GCMClientImplTest { |
688 public: | 688 public: |
689 GCMClientImplCheckinTest(); | 689 GCMClientImplCheckinTest(); |
690 virtual ~GCMClientImplCheckinTest(); | 690 virtual ~GCMClientImplCheckinTest(); |
691 | 691 |
692 virtual void SetUp() OVERRIDE; | 692 virtual void SetUp() OVERRIDE; |
693 | |
694 std::map<std::string, std::string> GenerateSettings(int64 checkin_interval); | |
695 }; | 693 }; |
696 | 694 |
697 GCMClientImplCheckinTest::GCMClientImplCheckinTest() { | 695 GCMClientImplCheckinTest::GCMClientImplCheckinTest() { |
698 } | 696 } |
699 | 697 |
700 GCMClientImplCheckinTest::~GCMClientImplCheckinTest() { | 698 GCMClientImplCheckinTest::~GCMClientImplCheckinTest() { |
701 } | 699 } |
702 | 700 |
703 void GCMClientImplCheckinTest::SetUp() { | 701 void GCMClientImplCheckinTest::SetUp() { |
704 testing::Test::SetUp(); | 702 testing::Test::SetUp(); |
(...skipping 10 matching lines...) Expand all Loading... |
715 InitializeGCMClient(); | 713 InitializeGCMClient(); |
716 } | 714 } |
717 | 715 |
718 TEST_F(GCMClientImplCheckinTest, GServicesSettingsAfterInitialCheckin) { | 716 TEST_F(GCMClientImplCheckinTest, GServicesSettingsAfterInitialCheckin) { |
719 std::map<std::string, std::string> settings; | 717 std::map<std::string, std::string> settings; |
720 settings["checkin_interval"] = base::Int64ToString(kSettingsCheckinInterval); | 718 settings["checkin_interval"] = base::Int64ToString(kSettingsCheckinInterval); |
721 settings["checkin_url"] = "http://alternative.url/checkin"; | 719 settings["checkin_url"] = "http://alternative.url/checkin"; |
722 settings["gcm_hostname"] = "alternative.gcm.host"; | 720 settings["gcm_hostname"] = "alternative.gcm.host"; |
723 settings["gcm_secure_port"] = "7777"; | 721 settings["gcm_secure_port"] = "7777"; |
724 settings["gcm_registration_url"] = "http://alternative.url/registration"; | 722 settings["gcm_registration_url"] = "http://alternative.url/registration"; |
725 CompleteCheckin( | 723 CompleteCheckin(kDeviceAndroidId, |
726 kDeviceAndroidId, kDeviceSecurityToken, kSettingsDefaultDigest, settings); | 724 kDeviceSecurityToken, |
| 725 GServicesSettings::CalculateDigest(settings), |
| 726 settings); |
727 EXPECT_EQ(base::TimeDelta::FromSeconds(kSettingsCheckinInterval), | 727 EXPECT_EQ(base::TimeDelta::FromSeconds(kSettingsCheckinInterval), |
728 gservices_settings().checkin_interval()); | 728 gservices_settings().GetCheckinInterval()); |
729 EXPECT_EQ(GURL("http://alternative.url/checkin"), | 729 EXPECT_EQ(GURL("http://alternative.url/checkin"), |
730 gservices_settings().checkin_url()); | 730 gservices_settings().GetCheckinURL()); |
731 EXPECT_EQ(GURL("http://alternative.url/registration"), | 731 EXPECT_EQ(GURL("http://alternative.url/registration"), |
732 gservices_settings().registration_url()); | 732 gservices_settings().GetRegistrationURL()); |
733 EXPECT_EQ(GURL("https://alternative.gcm.host:7777"), | 733 EXPECT_EQ(GURL("https://alternative.gcm.host:7777"), |
734 gservices_settings().mcs_main_endpoint()); | 734 gservices_settings().GetMCSMainEndpoint()); |
735 EXPECT_EQ(GURL("https://alternative.gcm.host:443"), | 735 EXPECT_EQ(GURL("https://alternative.gcm.host:443"), |
736 gservices_settings().mcs_fallback_endpoint()); | 736 gservices_settings().GetMCSFallbackEndpoint()); |
737 } | 737 } |
738 | 738 |
739 // This test only checks that periodic checkin happens. | 739 // This test only checks that periodic checkin happens. |
740 TEST_F(GCMClientImplCheckinTest, PeriodicCheckin) { | 740 TEST_F(GCMClientImplCheckinTest, PeriodicCheckin) { |
741 std::map<std::string, std::string> settings; | 741 std::map<std::string, std::string> settings; |
742 settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval); | 742 settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval); |
743 settings["checkin_url"] = "http://alternative.url/checkin"; | 743 settings["checkin_url"] = "http://alternative.url/checkin"; |
744 settings["gcm_hostname"] = "alternative.gcm.host"; | 744 settings["gcm_hostname"] = "alternative.gcm.host"; |
745 settings["gcm_secure_port"] = "7777"; | 745 settings["gcm_secure_port"] = "7777"; |
746 settings["gcm_registration_url"] = "http://alternative.url/registration"; | 746 settings["gcm_registration_url"] = "http://alternative.url/registration"; |
747 CompleteCheckin( | 747 CompleteCheckin(kDeviceAndroidId, |
748 kDeviceAndroidId, kDeviceSecurityToken, kSettingsDefaultDigest, settings); | 748 kDeviceSecurityToken, |
| 749 GServicesSettings::CalculateDigest(settings), |
| 750 settings); |
749 EXPECT_EQ(2, clock()->call_count()); | 751 EXPECT_EQ(2, clock()->call_count()); |
750 | 752 |
751 PumpLoopUntilIdle(); | 753 PumpLoopUntilIdle(); |
752 CompleteCheckin( | 754 CompleteCheckin(kDeviceAndroidId, |
753 kDeviceAndroidId, kDeviceSecurityToken, kSettingsDefaultDigest, settings); | 755 kDeviceSecurityToken, |
| 756 GServicesSettings::CalculateDigest(settings), |
| 757 settings); |
754 } | 758 } |
755 | 759 |
756 TEST_F(GCMClientImplCheckinTest, LoadGSettingsFromStore) { | 760 TEST_F(GCMClientImplCheckinTest, LoadGSettingsFromStore) { |
757 std::map<std::string, std::string> settings; | 761 std::map<std::string, std::string> settings; |
758 settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval); | 762 settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval); |
759 settings["checkin_url"] = "http://alternative.url/checkin"; | 763 settings["checkin_url"] = "http://alternative.url/checkin"; |
760 settings["gcm_hostname"] = "alternative.gcm.host"; | 764 settings["gcm_hostname"] = "alternative.gcm.host"; |
761 settings["gcm_secure_port"] = "7777"; | 765 settings["gcm_secure_port"] = "7777"; |
762 settings["gcm_registration_url"] = "http://alternative.url/registration"; | 766 settings["gcm_registration_url"] = "http://alternative.url/registration"; |
763 CompleteCheckin( | 767 CompleteCheckin(kDeviceAndroidId, |
764 kDeviceAndroidId, kDeviceSecurityToken, kSettingsDefaultDigest, settings); | 768 kDeviceSecurityToken, |
| 769 GServicesSettings::CalculateDigest(settings), |
| 770 settings); |
765 | 771 |
766 BuildGCMClient(base::TimeDelta()); | 772 BuildGCMClient(base::TimeDelta()); |
767 InitializeGCMClient(); | 773 InitializeGCMClient(); |
768 | 774 |
769 EXPECT_EQ(base::TimeDelta::FromSeconds(kSettingsCheckinInterval), | 775 EXPECT_EQ(base::TimeDelta::FromSeconds(kSettingsCheckinInterval), |
770 gservices_settings().checkin_interval()); | 776 gservices_settings().GetCheckinInterval()); |
771 EXPECT_EQ(GURL("http://alternative.url/checkin"), | 777 EXPECT_EQ(GURL("http://alternative.url/checkin"), |
772 gservices_settings().checkin_url()); | 778 gservices_settings().GetCheckinURL()); |
773 EXPECT_EQ(GURL("http://alternative.url/registration"), | 779 EXPECT_EQ(GURL("http://alternative.url/registration"), |
774 gservices_settings().registration_url()); | 780 gservices_settings().GetRegistrationURL()); |
775 EXPECT_EQ(GURL("https://alternative.gcm.host:7777"), | 781 EXPECT_EQ(GURL("https://alternative.gcm.host:7777"), |
776 gservices_settings().mcs_main_endpoint()); | 782 gservices_settings().GetMCSMainEndpoint()); |
777 EXPECT_EQ(GURL("https://alternative.gcm.host:443"), | 783 EXPECT_EQ(GURL("https://alternative.gcm.host:443"), |
778 gservices_settings().mcs_fallback_endpoint()); | 784 gservices_settings().GetMCSFallbackEndpoint()); |
779 } | 785 } |
780 | 786 |
781 } // namespace gcm | 787 } // namespace gcm |
OLD | NEW |