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

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

Issue 378643002: [GCM] Check-in with signed in accounts associates device to user (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixing compilation issue on android Created 6 years, 5 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
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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 virtual void OnDisconnected() OVERRIDE {} 255 virtual void OnDisconnected() OVERRIDE {}
256 256
257 GCMClientImpl* gcm_client() const { return gcm_client_.get(); } 257 GCMClientImpl* gcm_client() const { return gcm_client_.get(); }
258 FakeMCSClient* mcs_client() const { 258 FakeMCSClient* mcs_client() const {
259 return reinterpret_cast<FakeMCSClient*>(gcm_client_->mcs_client_.get()); 259 return reinterpret_cast<FakeMCSClient*>(gcm_client_->mcs_client_.get());
260 } 260 }
261 ConnectionFactory* connection_factory() const { 261 ConnectionFactory* connection_factory() const {
262 return gcm_client_->connection_factory_.get(); 262 return gcm_client_->connection_factory_.get();
263 } 263 }
264 264
265 const GCMClientImpl::CheckinInfo& device_checkin_info() const {
266 return gcm_client_->device_checkin_info_;
267 }
268
265 void reset_last_event() { 269 void reset_last_event() {
266 last_event_ = NONE; 270 last_event_ = NONE;
267 last_app_id_.clear(); 271 last_app_id_.clear();
268 last_registration_id_.clear(); 272 last_registration_id_.clear();
269 last_message_id_.clear(); 273 last_message_id_.clear();
270 last_result_ = GCMClient::UNKNOWN_ERROR; 274 last_result_ = GCMClient::UNKNOWN_ERROR;
271 } 275 }
272 276
273 LastEvent last_event() const { return last_event_; } 277 LastEvent last_event() const { return last_event_; }
274 const std::string& last_app_id() const { return last_app_id_; } 278 const std::string& last_app_id() const { return last_app_id_; }
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 } 516 }
513 517
514 int64 GCMClientImplTest::CurrentTime() { 518 int64 GCMClientImplTest::CurrentTime() {
515 return clock()->Now().ToInternalValue() / base::Time::kMicrosecondsPerSecond; 519 return clock()->Now().ToInternalValue() / base::Time::kMicrosecondsPerSecond;
516 } 520 }
517 521
518 TEST_F(GCMClientImplTest, LoadingCompleted) { 522 TEST_F(GCMClientImplTest, LoadingCompleted) {
519 EXPECT_EQ(LOADING_COMPLETED, last_event()); 523 EXPECT_EQ(LOADING_COMPLETED, last_event());
520 EXPECT_EQ(kDeviceAndroidId, mcs_client()->last_android_id()); 524 EXPECT_EQ(kDeviceAndroidId, mcs_client()->last_android_id());
521 EXPECT_EQ(kDeviceSecurityToken, mcs_client()->last_security_token()); 525 EXPECT_EQ(kDeviceSecurityToken, mcs_client()->last_security_token());
526
527 // Checking freshly loaded CheckinInfo.
528 EXPECT_EQ(kDeviceAndroidId, device_checkin_info().android_id);
529 EXPECT_EQ(kDeviceSecurityToken, device_checkin_info().secret);
530 EXPECT_EQ(0UL, device_checkin_info().last_checkin_accounts_count);
531 EXPECT_TRUE(device_checkin_info().accounts_set);
532 EXPECT_TRUE(device_checkin_info().account_tokens.empty());
522 } 533 }
523 534
524 TEST_F(GCMClientImplTest, CheckOut) { 535 TEST_F(GCMClientImplTest, CheckOut) {
525 EXPECT_TRUE(mcs_client()); 536 EXPECT_TRUE(mcs_client());
526 EXPECT_TRUE(connection_factory()); 537 EXPECT_TRUE(connection_factory());
527 gcm_client()->CheckOut(); 538 gcm_client()->CheckOut();
528 EXPECT_FALSE(mcs_client()); 539 EXPECT_FALSE(mcs_client());
529 EXPECT_FALSE(connection_factory()); 540 EXPECT_FALSE(connection_factory());
530 } 541 }
531 542
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 std::map<std::string, std::string> settings; 752 std::map<std::string, std::string> settings;
742 settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval); 753 settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval);
743 settings["checkin_url"] = "http://alternative.url/checkin"; 754 settings["checkin_url"] = "http://alternative.url/checkin";
744 settings["gcm_hostname"] = "alternative.gcm.host"; 755 settings["gcm_hostname"] = "alternative.gcm.host";
745 settings["gcm_secure_port"] = "7777"; 756 settings["gcm_secure_port"] = "7777";
746 settings["gcm_registration_url"] = "http://alternative.url/registration"; 757 settings["gcm_registration_url"] = "http://alternative.url/registration";
747 CompleteCheckin(kDeviceAndroidId, 758 CompleteCheckin(kDeviceAndroidId,
748 kDeviceSecurityToken, 759 kDeviceSecurityToken,
749 GServicesSettings::CalculateDigest(settings), 760 GServicesSettings::CalculateDigest(settings),
750 settings); 761 settings);
762
751 EXPECT_EQ(2, clock()->call_count()); 763 EXPECT_EQ(2, clock()->call_count());
752 764
753 PumpLoopUntilIdle(); 765 PumpLoopUntilIdle();
754 CompleteCheckin(kDeviceAndroidId, 766 CompleteCheckin(kDeviceAndroidId,
755 kDeviceSecurityToken, 767 kDeviceSecurityToken,
756 GServicesSettings::CalculateDigest(settings), 768 GServicesSettings::CalculateDigest(settings),
757 settings); 769 settings);
758 } 770 }
759 771
760 TEST_F(GCMClientImplCheckinTest, LoadGSettingsFromStore) { 772 TEST_F(GCMClientImplCheckinTest, LoadGSettingsFromStore) {
(...skipping 17 matching lines...) Expand all
778 EXPECT_EQ(GURL("http://alternative.url/checkin"), 790 EXPECT_EQ(GURL("http://alternative.url/checkin"),
779 gservices_settings().GetCheckinURL()); 791 gservices_settings().GetCheckinURL());
780 EXPECT_EQ(GURL("http://alternative.url/registration"), 792 EXPECT_EQ(GURL("http://alternative.url/registration"),
781 gservices_settings().GetRegistrationURL()); 793 gservices_settings().GetRegistrationURL());
782 EXPECT_EQ(GURL("https://alternative.gcm.host:7777"), 794 EXPECT_EQ(GURL("https://alternative.gcm.host:7777"),
783 gservices_settings().GetMCSMainEndpoint()); 795 gservices_settings().GetMCSMainEndpoint());
784 EXPECT_EQ(GURL("https://alternative.gcm.host:443"), 796 EXPECT_EQ(GURL("https://alternative.gcm.host:443"),
785 gservices_settings().GetMCSFallbackEndpoint()); 797 gservices_settings().GetMCSFallbackEndpoint());
786 } 798 }
787 799
800 // This test only checks that periodic checkin happens.
801 TEST_F(GCMClientImplCheckinTest, CheckinWithAccounts) {
802 std::map<std::string, std::string> settings;
803 settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval);
804 settings["checkin_url"] = "http://alternative.url/checkin";
805 settings["gcm_hostname"] = "alternative.gcm.host";
806 settings["gcm_secure_port"] = "7777";
807 settings["gcm_registration_url"] = "http://alternative.url/registration";
808 CompleteCheckin(kDeviceAndroidId,
809 kDeviceSecurityToken,
810 GServicesSettings::CalculateDigest(settings),
811 settings);
812
813 std::map<std::string, std::string> account_tokens;
814 account_tokens["test_user1@gmail.com"] = "token1";
815 account_tokens["test_user2@gmail.com"] = "token2";
816 gcm_client()->SetAccountsForCheckin(account_tokens, false);
817
818 EXPECT_EQ(0UL, device_checkin_info().last_checkin_accounts_count);
819 EXPECT_TRUE(device_checkin_info().accounts_set);
820 EXPECT_EQ(account_tokens, device_checkin_info().account_tokens);
821
822 PumpLoopUntilIdle();
823 CompleteCheckin(kDeviceAndroidId,
824 kDeviceSecurityToken,
825 GServicesSettings::CalculateDigest(settings),
826 settings);
827
828 EXPECT_EQ(2UL, device_checkin_info().last_checkin_accounts_count);
829 EXPECT_TRUE(device_checkin_info().accounts_set);
830 EXPECT_EQ(account_tokens, device_checkin_info().account_tokens);
831 }
832
833 // This test only checks that periodic checkin happens.
834 TEST_F(GCMClientImplCheckinTest, CheckinWhenAccountRemoved) {
835 std::map<std::string, std::string> settings;
836 settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval);
837 settings["checkin_url"] = "http://alternative.url/checkin";
838 settings["gcm_hostname"] = "alternative.gcm.host";
839 settings["gcm_secure_port"] = "7777";
840 settings["gcm_registration_url"] = "http://alternative.url/registration";
841 CompleteCheckin(kDeviceAndroidId,
842 kDeviceSecurityToken,
843 GServicesSettings::CalculateDigest(settings),
844 settings);
845
846 std::map<std::string, std::string> account_tokens;
847 account_tokens["test_user1@gmail.com"] = "token1";
848 gcm_client()->SetAccountsForCheckin(account_tokens, true);
849
850 EXPECT_EQ(1UL, device_checkin_info().last_checkin_accounts_count);
851 EXPECT_TRUE(device_checkin_info().accounts_set);
852 EXPECT_EQ(account_tokens, device_checkin_info().account_tokens);
853
854 PumpLoopUntilIdle();
855 CompleteCheckin(kDeviceAndroidId,
856 kDeviceSecurityToken,
857 GServicesSettings::CalculateDigest(settings),
858 settings);
859
860 EXPECT_EQ(1UL, device_checkin_info().last_checkin_accounts_count);
861 EXPECT_TRUE(device_checkin_info().accounts_set);
862 EXPECT_EQ(account_tokens, device_checkin_info().account_tokens);
863 }
864
865 // This test only checks that periodic checkin happens.
866 TEST_F(GCMClientImplCheckinTest, CheckinWhenAccountRemovalImplied) {
867 std::map<std::string, std::string> settings;
868 settings["checkin_interval"] = base::IntToString(kSettingsCheckinInterval);
869 settings["checkin_url"] = "http://alternative.url/checkin";
870 settings["gcm_hostname"] = "alternative.gcm.host";
871 settings["gcm_secure_port"] = "7777";
872 settings["gcm_registration_url"] = "http://alternative.url/registration";
873 CompleteCheckin(kDeviceAndroidId,
874 kDeviceSecurityToken,
875 GServicesSettings::CalculateDigest(settings),
876 settings);
877
878 std::map<std::string, std::string> account_tokens;
879 account_tokens["test_user1@gmail.com"] = "token1";
880 account_tokens["test_user2@gmail.com"] = "token2";
881 gcm_client()->SetAccountsForCheckin(account_tokens, false);
882
883 PumpLoopUntilIdle();
884 CompleteCheckin(kDeviceAndroidId,
885 kDeviceSecurityToken,
886 GServicesSettings::CalculateDigest(settings),
887 settings);
888
889 EXPECT_EQ(2UL, device_checkin_info().last_checkin_accounts_count);
890
891 // This should trigger another checkin, because there is less account tokens,
892 // than last reported. This could happen on a restart.
893 account_tokens.erase(account_tokens.find("test_user1@gmail.com"));
894 gcm_client()->SetAccountsForCheckin(account_tokens, false);
895
896 EXPECT_EQ(1UL, device_checkin_info().last_checkin_accounts_count);
897 EXPECT_TRUE(device_checkin_info().accounts_set);
898 EXPECT_EQ(account_tokens, device_checkin_info().account_tokens);
899
900 PumpLoopUntilIdle();
901 CompleteCheckin(kDeviceAndroidId,
902 kDeviceSecurityToken,
903 GServicesSettings::CalculateDigest(settings),
904 settings);
905
906 EXPECT_EQ(1UL, device_checkin_info().last_checkin_accounts_count);
907 EXPECT_TRUE(device_checkin_info().accounts_set);
908 EXPECT_EQ(account_tokens, device_checkin_info().account_tokens);
909 }
910
788 class GCMClientImplStartAndStopTest : public GCMClientImplTest { 911 class GCMClientImplStartAndStopTest : public GCMClientImplTest {
789 public: 912 public:
790 GCMClientImplStartAndStopTest(); 913 GCMClientImplStartAndStopTest();
791 virtual ~GCMClientImplStartAndStopTest(); 914 virtual ~GCMClientImplStartAndStopTest();
792 915
793 virtual void SetUp() OVERRIDE; 916 virtual void SetUp() OVERRIDE;
794 }; 917 };
795 918
796 GCMClientImplStartAndStopTest::GCMClientImplStartAndStopTest() { 919 GCMClientImplStartAndStopTest::GCMClientImplStartAndStopTest() {
797 } 920 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 TEST_F(GCMClientImplStartAndStopTest, StartStopAndRestartImmediately) { 955 TEST_F(GCMClientImplStartAndStopTest, StartStopAndRestartImmediately) {
833 // Start the GCM and then stop and restart it immediately. 956 // Start the GCM and then stop and restart it immediately.
834 gcm_client()->Start(); 957 gcm_client()->Start();
835 gcm_client()->Stop(); 958 gcm_client()->Stop();
836 gcm_client()->Start(); 959 gcm_client()->Start();
837 960
838 PumpLoopUntilIdle(); 961 PumpLoopUntilIdle();
839 } 962 }
840 963
841 } // namespace gcm 964 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698