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