| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <map> | 6 #include <map> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 waiter_->PumpUILoop(); | 353 waiter_->PumpUILoop(); |
| 354 } | 354 } |
| 355 | 355 |
| 356 void SignOut() { | 356 void SignOut() { |
| 357 signin_manager_->SignOut(); | 357 signin_manager_->SignOut(); |
| 358 waiter_->PumpIOLoop(); | 358 waiter_->PumpIOLoop(); |
| 359 waiter_->PumpUILoop(); | 359 waiter_->PumpUILoop(); |
| 360 } | 360 } |
| 361 | 361 |
| 362 void Register(const std::string& app_id, | 362 void Register(const std::string& app_id, |
| 363 const std::vector<std::string>& sender_ids) { | 363 const std::string& sender_id) { |
| 364 GetGCMProfileService()->Register( | 364 GetGCMProfileService()->Register( |
| 365 app_id, | 365 app_id, |
| 366 sender_ids, | 366 sender_id, |
| 367 kTestingSha1Cert, | 367 kTestingSha1Cert, |
| 368 base::Bind(&GCMProfileServiceTestConsumer::RegisterCompleted, | 368 base::Bind(&GCMProfileServiceTestConsumer::RegisterCompleted, |
| 369 base::Unretained(this))); | 369 base::Unretained(this))); |
| 370 } | 370 } |
| 371 | 371 |
| 372 void RegisterCompleted(const std::string& registration_id, | 372 void RegisterCompleted(const std::string& registration_id, |
| 373 GCMClient::Result result) { | 373 GCMClient::Result result) { |
| 374 registration_id_ = registration_id; | 374 registration_id_ = registration_id; |
| 375 registration_result_ = result; | 375 registration_result_ = result; |
| 376 waiter_->SignalCompleted(); | 376 waiter_->SignalCompleted(); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 consumer()->SignIn(kTestingUsername2); | 645 consumer()->SignIn(kTestingUsername2); |
| 646 | 646 |
| 647 // GCMClient should be loaded again. | 647 // GCMClient should be loaded again. |
| 648 EXPECT_TRUE(consumer()->IsGCMClientReady()); | 648 EXPECT_TRUE(consumer()->IsGCMClientReady()); |
| 649 EXPECT_EQ(GCMClientMock::LOADED, consumer()->GetGCMClient()->status()); | 649 EXPECT_EQ(GCMClientMock::LOADED, consumer()->GetGCMClient()->status()); |
| 650 } | 650 } |
| 651 | 651 |
| 652 TEST_F(GCMProfileServiceTest, RegisterWhenNotSignedIn) { | 652 TEST_F(GCMProfileServiceTest, RegisterWhenNotSignedIn) { |
| 653 consumer()->CreateGCMProfileServiceInstance(); | 653 consumer()->CreateGCMProfileServiceInstance(); |
| 654 | 654 |
| 655 std::vector<std::string> sender_ids; | 655 consumer()->Register(kTestingAppId, "sender1"); |
| 656 sender_ids.push_back("sender1"); | |
| 657 consumer()->Register(kTestingAppId, sender_ids); | |
| 658 | 656 |
| 659 EXPECT_TRUE(consumer()->registration_id().empty()); | 657 EXPECT_TRUE(consumer()->registration_id().empty()); |
| 660 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, consumer()->registration_result()); | 658 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, consumer()->registration_result()); |
| 661 } | 659 } |
| 662 | 660 |
| 663 TEST_F(GCMProfileServiceTest, RegisterUnderNeutralChannelSignal) { | 661 TEST_F(GCMProfileServiceTest, RegisterUnderNeutralChannelSignal) { |
| 664 // Neutral channel signal will prevent GCMClient from checking in when the | 662 // Neutral channel signal will prevent GCMClient from checking in when the |
| 665 // profile is signed in. | 663 // profile is signed in. |
| 666 profile()->GetPrefs()->ClearPref(prefs::kGCMChannelEnabled); | 664 profile()->GetPrefs()->ClearPref(prefs::kGCMChannelEnabled); |
| 667 | 665 |
| 668 consumer()->CreateGCMProfileServiceInstance(); | 666 consumer()->CreateGCMProfileServiceInstance(); |
| 669 consumer()->SignIn(kTestingUsername); | 667 consumer()->SignIn(kTestingUsername); |
| 670 | 668 |
| 671 // GCMClient should not be checked in. | 669 // GCMClient should not be checked in. |
| 672 EXPECT_FALSE(consumer()->IsGCMClientReady()); | 670 EXPECT_FALSE(consumer()->IsGCMClientReady()); |
| 673 EXPECT_EQ(GCMClientMock::UNINITIALIZED, consumer()->GetGCMClient()->status()); | 671 EXPECT_EQ(GCMClientMock::UNINITIALIZED, consumer()->GetGCMClient()->status()); |
| 674 | 672 |
| 675 // Invoking register will make GCMClient checked in. | 673 // Invoking register will make GCMClient checked in. |
| 676 std::vector<std::string> sender_ids; | 674 consumer()->Register(kTestingAppId, "sender1"); |
| 677 sender_ids.push_back("sender1"); | |
| 678 consumer()->Register(kTestingAppId, sender_ids); | |
| 679 WaitUntilCompleted(); | 675 WaitUntilCompleted(); |
| 680 | 676 |
| 681 // GCMClient should be checked in. | 677 // GCMClient should be checked in. |
| 682 EXPECT_TRUE(consumer()->IsGCMClientReady()); | 678 EXPECT_TRUE(consumer()->IsGCMClientReady()); |
| 683 EXPECT_EQ(GCMClientMock::LOADED, consumer()->GetGCMClient()->status()); | 679 EXPECT_EQ(GCMClientMock::LOADED, consumer()->GetGCMClient()->status()); |
| 684 | 680 |
| 685 // Registration should succeed. | 681 // Registration should succeed. |
| 686 std::string expected_registration_id = | 682 std::string expected_registration_id = |
| 687 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids); | 683 GCMClientMock::GetRegistrationIdFromSenderId("sender1"); |
| 688 EXPECT_EQ(expected_registration_id, consumer()->registration_id()); | 684 EXPECT_EQ(expected_registration_id, consumer()->registration_id()); |
| 689 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 685 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 690 } | 686 } |
| 691 | 687 |
| 692 TEST_F(GCMProfileServiceTest, SendWhenNotSignedIn) { | 688 TEST_F(GCMProfileServiceTest, SendWhenNotSignedIn) { |
| 693 consumer()->CreateGCMProfileServiceInstance(); | 689 consumer()->CreateGCMProfileServiceInstance(); |
| 694 | 690 |
| 695 GCMClient::OutgoingMessage message; | 691 GCMClient::OutgoingMessage message; |
| 696 message.id = "1"; | 692 message.id = "1"; |
| 697 message.data["key1"] = "value1"; | 693 message.data["key1"] = "value1"; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 | 736 |
| 741 virtual void SetUp() OVERRIDE { | 737 virtual void SetUp() OVERRIDE { |
| 742 GCMProfileServiceTest::SetUp(); | 738 GCMProfileServiceTest::SetUp(); |
| 743 | 739 |
| 744 consumer()->CreateGCMProfileServiceInstance(); | 740 consumer()->CreateGCMProfileServiceInstance(); |
| 745 consumer()->SignIn(kTestingUsername); | 741 consumer()->SignIn(kTestingUsername); |
| 746 } | 742 } |
| 747 }; | 743 }; |
| 748 | 744 |
| 749 TEST_F(GCMProfileServiceSingleProfileTest, Register) { | 745 TEST_F(GCMProfileServiceSingleProfileTest, Register) { |
| 750 std::vector<std::string> sender_ids; | 746 consumer()->Register(kTestingAppId, "sender1"); |
| 751 sender_ids.push_back("sender1"); | |
| 752 consumer()->Register(kTestingAppId, sender_ids); | |
| 753 std::string expected_registration_id = | 747 std::string expected_registration_id = |
| 754 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids); | 748 GCMClientMock::GetRegistrationIdFromSenderId("sender1"); |
| 755 | 749 |
| 756 WaitUntilCompleted(); | 750 WaitUntilCompleted(); |
| 757 EXPECT_EQ(expected_registration_id, consumer()->registration_id()); | 751 EXPECT_EQ(expected_registration_id, consumer()->registration_id()); |
| 758 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 752 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 759 } | 753 } |
| 760 | 754 |
| 761 TEST_F(GCMProfileServiceSingleProfileTest, DoubleRegister) { | 755 TEST_F(GCMProfileServiceSingleProfileTest, DoubleRegister) { |
| 762 std::vector<std::string> sender_ids; | 756 consumer()->Register(kTestingAppId, "sender1"); |
| 763 sender_ids.push_back("sender1"); | |
| 764 consumer()->Register(kTestingAppId, sender_ids); | |
| 765 std::string expected_registration_id = | 757 std::string expected_registration_id = |
| 766 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids); | 758 GCMClientMock::GetRegistrationIdFromSenderId("sender1"); |
| 767 | 759 |
| 768 // Calling regsiter 2nd time without waiting 1st one to finish will fail | 760 // Calling regsiter 2nd time without waiting 1st one to finish will fail |
| 769 // immediately. | 761 // immediately. |
| 770 sender_ids.push_back("sender2"); | 762 consumer()->Register(kTestingAppId, "sender2"); |
| 771 consumer()->Register(kTestingAppId, sender_ids); | |
| 772 EXPECT_TRUE(consumer()->registration_id().empty()); | 763 EXPECT_TRUE(consumer()->registration_id().empty()); |
| 773 EXPECT_EQ(GCMClient::ASYNC_OPERATION_PENDING, | 764 EXPECT_EQ(GCMClient::ASYNC_OPERATION_PENDING, |
| 774 consumer()->registration_result()); | 765 consumer()->registration_result()); |
| 775 | 766 |
| 776 // The 1st register is still doing fine. | 767 // The 1st register is still doing fine. |
| 777 WaitUntilCompleted(); | 768 WaitUntilCompleted(); |
| 778 EXPECT_EQ(expected_registration_id, consumer()->registration_id()); | 769 EXPECT_EQ(expected_registration_id, consumer()->registration_id()); |
| 779 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 770 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 780 } | 771 } |
| 781 | 772 |
| 782 TEST_F(GCMProfileServiceSingleProfileTest, RegisterError) { | 773 TEST_F(GCMProfileServiceSingleProfileTest, RegisterError) { |
| 783 std::vector<std::string> sender_ids; | 774 consumer()->Register(kTestingAppId, "sender1@error"); |
| 784 sender_ids.push_back("sender1@error"); | |
| 785 consumer()->Register(kTestingAppId, sender_ids); | |
| 786 | 775 |
| 787 WaitUntilCompleted(); | 776 WaitUntilCompleted(); |
| 788 EXPECT_TRUE(consumer()->registration_id().empty()); | 777 EXPECT_TRUE(consumer()->registration_id().empty()); |
| 789 EXPECT_NE(GCMClient::SUCCESS, consumer()->registration_result()); | 778 EXPECT_NE(GCMClient::SUCCESS, consumer()->registration_result()); |
| 790 } | 779 } |
| 791 | 780 |
| 792 TEST_F(GCMProfileServiceSingleProfileTest, RegisterAgainWithSameSenderIDs) { | 781 TEST_F(GCMProfileServiceSingleProfileTest, RegisterAgainWithSameSenderID) { |
| 793 std::vector<std::string> sender_ids; | 782 consumer()->Register(kTestingAppId, "sender1"); |
| 794 sender_ids.push_back("sender1"); | |
| 795 sender_ids.push_back("sender2"); | |
| 796 consumer()->Register(kTestingAppId, sender_ids); | |
| 797 std::string expected_registration_id = | 783 std::string expected_registration_id = |
| 798 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids); | 784 GCMClientMock::GetRegistrationIdFromSenderId("sender1"); |
| 799 | 785 |
| 800 WaitUntilCompleted(); | 786 WaitUntilCompleted(); |
| 801 EXPECT_EQ(expected_registration_id, consumer()->registration_id()); | 787 EXPECT_EQ(expected_registration_id, consumer()->registration_id()); |
| 802 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 788 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 803 | 789 |
| 804 // Clears the results the would be set by the Register callback in preparation | 790 // Clears the results the would be set by the Register callback in preparation |
| 805 // to call register 2nd time. | 791 // to call register 2nd time. |
| 806 consumer()->clear_registration_result(); | 792 consumer()->clear_registration_result(); |
| 807 | 793 |
| 808 // Calling register 2nd time with the same set of sender IDs but different | 794 // Calling register 2nd time will get back the same registration ID. There is |
| 809 // ordering will get back the same registration ID. There is no need to wait | 795 // no need to wait since register simply returns the cached registration ID. |
| 810 // since register simply returns the cached registration ID. | 796 consumer()->Register(kTestingAppId, "sender1"); |
| 811 std::vector<std::string> another_sender_ids; | |
| 812 another_sender_ids.push_back("sender2"); | |
| 813 another_sender_ids.push_back("sender1"); | |
| 814 consumer()->Register(kTestingAppId, another_sender_ids); | |
| 815 EXPECT_EQ(expected_registration_id, consumer()->registration_id()); | 797 EXPECT_EQ(expected_registration_id, consumer()->registration_id()); |
| 816 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 798 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 817 } | 799 } |
| 818 | 800 |
| 819 TEST_F(GCMProfileServiceSingleProfileTest, | 801 TEST_F(GCMProfileServiceSingleProfileTest, |
| 820 RegisterAgainWithDifferentSenderIDs) { | 802 RegisterAgainWithDifferentSenderID) { |
| 821 std::vector<std::string> sender_ids; | 803 consumer()->Register(kTestingAppId, "sender1"); |
| 822 sender_ids.push_back("sender1"); | |
| 823 consumer()->Register(kTestingAppId, sender_ids); | |
| 824 std::string expected_registration_id = | 804 std::string expected_registration_id = |
| 825 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids); | 805 GCMClientMock::GetRegistrationIdFromSenderId("sender1"); |
| 826 | 806 |
| 827 WaitUntilCompleted(); | 807 WaitUntilCompleted(); |
| 828 EXPECT_EQ(expected_registration_id, consumer()->registration_id()); | 808 EXPECT_EQ(expected_registration_id, consumer()->registration_id()); |
| 829 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 809 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 830 | 810 |
| 831 // Make sender IDs different. | 811 // Make sender ID different. |
| 832 sender_ids.push_back("sender2"); | |
| 833 std::string expected_registration_id2 = | 812 std::string expected_registration_id2 = |
| 834 GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids); | 813 GCMClientMock::GetRegistrationIdFromSenderId("sender2"); |
| 835 | 814 |
| 836 // Calling register 2nd time with the different sender IDs will get back a new | 815 // Calling register 2nd time with a different sender ID will get back a new |
| 837 // registration ID. | 816 // registration ID. |
| 838 consumer()->Register(kTestingAppId, sender_ids); | 817 consumer()->Register(kTestingAppId, "sender2"); |
| 839 WaitUntilCompleted(); | 818 WaitUntilCompleted(); |
| 840 EXPECT_EQ(expected_registration_id2, consumer()->registration_id()); | 819 EXPECT_EQ(expected_registration_id2, consumer()->registration_id()); |
| 841 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 820 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 842 } | 821 } |
| 843 | 822 |
| 844 TEST_F(GCMProfileServiceSingleProfileTest, ReadRegistrationFromStateStore) { | 823 TEST_F(GCMProfileServiceSingleProfileTest, ReadRegistrationFromStateStore) { |
| 845 scoped_refptr<Extension> extension(consumer()->CreateExtension()); | 824 scoped_refptr<Extension> extension(consumer()->CreateExtension()); |
| 846 | 825 |
| 847 std::vector<std::string> sender_ids; | 826 consumer()->Register(extension->id(), "sender1"); |
| 848 sender_ids.push_back("sender1"); | |
| 849 consumer()->Register(extension->id(), sender_ids); | |
| 850 | 827 |
| 851 WaitUntilCompleted(); | 828 WaitUntilCompleted(); |
| 852 EXPECT_FALSE(consumer()->registration_id().empty()); | 829 EXPECT_FALSE(consumer()->registration_id().empty()); |
| 853 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 830 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 854 std::string old_registration_id = consumer()->registration_id(); | 831 std::string old_registration_id = consumer()->registration_id(); |
| 855 | 832 |
| 856 // Clears the results that would be set by the Register callback in | 833 // Clears the results that would be set by the Register callback in |
| 857 // preparation to call register 2nd time. | 834 // preparation to call register 2nd time. |
| 858 consumer()->clear_registration_result(); | 835 consumer()->clear_registration_result(); |
| 859 | 836 |
| 860 // Register should not reach the server. Forcing GCMClient server error should | 837 // Register should not reach the server. Forcing GCMClient server error should |
| 861 // help catch this. | 838 // help catch this. |
| 862 consumer()->set_gcm_client_error_simulation(GCMClientMock::FORCE_ERROR); | 839 consumer()->set_gcm_client_error_simulation(GCMClientMock::FORCE_ERROR); |
| 863 | 840 |
| 864 // Simulate start-up by recreating GCMProfileService. | 841 // Simulate start-up by recreating GCMProfileService. |
| 865 consumer()->CreateGCMProfileServiceInstance(); | 842 consumer()->CreateGCMProfileServiceInstance(); |
| 866 | 843 |
| 867 // Simulate start-up by reloading extension. | 844 // Simulate start-up by reloading extension. |
| 868 consumer()->ReloadExtension(extension); | 845 consumer()->ReloadExtension(extension); |
| 869 | 846 |
| 870 // This should read the registration info from the extension's state store. | 847 // This should read the registration info from the extension's state store. |
| 871 consumer()->Register(extension->id(), sender_ids); | 848 consumer()->Register(extension->id(), "sender1"); |
| 872 PumpIOLoop(); | 849 PumpIOLoop(); |
| 873 PumpUILoop(); | 850 PumpUILoop(); |
| 874 EXPECT_EQ(old_registration_id, consumer()->registration_id()); | 851 EXPECT_EQ(old_registration_id, consumer()->registration_id()); |
| 875 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 852 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 876 } | 853 } |
| 877 | 854 |
| 878 TEST_F(GCMProfileServiceSingleProfileTest, | 855 TEST_F(GCMProfileServiceSingleProfileTest, |
| 879 GCMClientReadyAfterReadingRegistration) { | 856 GCMClientReadyAfterReadingRegistration) { |
| 880 scoped_refptr<Extension> extension(consumer()->CreateExtension()); | 857 scoped_refptr<Extension> extension(consumer()->CreateExtension()); |
| 881 | 858 |
| 882 std::vector<std::string> sender_ids; | 859 consumer()->Register(extension->id(), "sender1"); |
| 883 sender_ids.push_back("sender1"); | |
| 884 consumer()->Register(extension->id(), sender_ids); | |
| 885 | 860 |
| 886 WaitUntilCompleted(); | 861 WaitUntilCompleted(); |
| 887 EXPECT_FALSE(consumer()->registration_id().empty()); | 862 EXPECT_FALSE(consumer()->registration_id().empty()); |
| 888 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 863 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 889 std::string old_registration_id = consumer()->registration_id(); | 864 std::string old_registration_id = consumer()->registration_id(); |
| 890 | 865 |
| 891 // Clears the results that would be set by the Register callback in | 866 // Clears the results that would be set by the Register callback in |
| 892 // preparation to call register 2nd time. | 867 // preparation to call register 2nd time. |
| 893 consumer()->clear_registration_result(); | 868 consumer()->clear_registration_result(); |
| 894 | 869 |
| 895 // Simulate start-up by recreating GCMProfileService. | 870 // Simulate start-up by recreating GCMProfileService. |
| 896 consumer()->set_gcm_client_loading_delay(GCMClientMock::DELAY_LOADING); | 871 consumer()->set_gcm_client_loading_delay(GCMClientMock::DELAY_LOADING); |
| 897 consumer()->CreateGCMProfileServiceInstance(); | 872 consumer()->CreateGCMProfileServiceInstance(); |
| 898 | 873 |
| 899 // Simulate start-up by reloading extension. | 874 // Simulate start-up by reloading extension. |
| 900 consumer()->ReloadExtension(extension); | 875 consumer()->ReloadExtension(extension); |
| 901 | 876 |
| 902 // Read the registration info from the extension's state store. | 877 // Read the registration info from the extension's state store. |
| 903 // This would hold up because GCMClient is in loading state. | 878 // This would hold up because GCMClient is in loading state. |
| 904 consumer()->Register(extension->id(), sender_ids); | 879 consumer()->Register(extension->id(), "sender1"); |
| 905 base::RunLoop().RunUntilIdle(); | 880 base::RunLoop().RunUntilIdle(); |
| 906 EXPECT_TRUE(consumer()->registration_id().empty()); | 881 EXPECT_TRUE(consumer()->registration_id().empty()); |
| 907 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, consumer()->registration_result()); | 882 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, consumer()->registration_result()); |
| 908 | 883 |
| 909 // Register operation will be invoked after GCMClient becomes ready. | 884 // Register operation will be invoked after GCMClient becomes ready. |
| 910 consumer()->GetGCMClient()->PerformDelayedLoading(); | 885 consumer()->GetGCMClient()->PerformDelayedLoading(); |
| 911 WaitUntilCompleted(); | 886 WaitUntilCompleted(); |
| 912 EXPECT_EQ(old_registration_id, consumer()->registration_id()); | 887 EXPECT_EQ(old_registration_id, consumer()->registration_id()); |
| 913 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 888 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 914 } | 889 } |
| 915 | 890 |
| 916 TEST_F(GCMProfileServiceSingleProfileTest, | 891 TEST_F(GCMProfileServiceSingleProfileTest, |
| 917 PersistedRegistrationInfoRemoveAfterSignOut) { | 892 PersistedRegistrationInfoRemoveAfterSignOut) { |
| 918 std::vector<std::string> sender_ids; | 893 consumer()->Register(kTestingAppId, "sender1"); |
| 919 sender_ids.push_back("sender1"); | |
| 920 consumer()->Register(kTestingAppId, sender_ids); | |
| 921 WaitUntilCompleted(); | 894 WaitUntilCompleted(); |
| 922 | 895 |
| 923 // The app id and registration info should be persisted. | 896 // The app id and registration info should be persisted. |
| 924 EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath(prefs::kGCMRegisteredAppIDs)); | 897 EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath(prefs::kGCMRegisteredAppIDs)); |
| 925 EXPECT_TRUE(consumer()->HasPersistedRegistrationInfo(kTestingAppId)); | 898 EXPECT_TRUE(consumer()->HasPersistedRegistrationInfo(kTestingAppId)); |
| 926 | 899 |
| 927 consumer()->SignOut(); | 900 consumer()->SignOut(); |
| 928 PumpUILoop(); | 901 PumpUILoop(); |
| 929 | 902 |
| 930 // The app id and persisted registration info should be removed. | 903 // The app id and persisted registration info should be removed. |
| 931 EXPECT_FALSE(profile()->GetPrefs()->HasPrefPath(prefs::kGCMRegisteredAppIDs)); | 904 EXPECT_FALSE(profile()->GetPrefs()->HasPrefPath(prefs::kGCMRegisteredAppIDs)); |
| 932 EXPECT_FALSE(consumer()->HasPersistedRegistrationInfo(kTestingAppId)); | 905 EXPECT_FALSE(consumer()->HasPersistedRegistrationInfo(kTestingAppId)); |
| 933 } | 906 } |
| 934 | 907 |
| 935 TEST_F(GCMProfileServiceSingleProfileTest, RegisterAfterSignOut) { | 908 TEST_F(GCMProfileServiceSingleProfileTest, RegisterAfterSignOut) { |
| 936 // This will trigger check-out. | 909 // This will trigger check-out. |
| 937 consumer()->SignOut(); | 910 consumer()->SignOut(); |
| 938 | 911 |
| 939 std::vector<std::string> sender_ids; | 912 consumer()->Register(kTestingAppId, "sender1"); |
| 940 sender_ids.push_back("sender1"); | |
| 941 consumer()->Register(kTestingAppId, sender_ids); | |
| 942 | 913 |
| 943 EXPECT_TRUE(consumer()->registration_id().empty()); | 914 EXPECT_TRUE(consumer()->registration_id().empty()); |
| 944 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, consumer()->registration_result()); | 915 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, consumer()->registration_result()); |
| 945 } | 916 } |
| 946 | 917 |
| 947 TEST_F(GCMProfileServiceSingleProfileTest, Unregister) { | 918 TEST_F(GCMProfileServiceSingleProfileTest, Unregister) { |
| 948 scoped_refptr<Extension> extension(consumer()->CreateExtension()); | 919 scoped_refptr<Extension> extension(consumer()->CreateExtension()); |
| 949 | 920 |
| 950 std::vector<std::string> sender_ids; | 921 consumer()->Register(extension->id(), "sender1"); |
| 951 sender_ids.push_back("sender1"); | |
| 952 consumer()->Register(extension->id(), sender_ids); | |
| 953 | 922 |
| 954 WaitUntilCompleted(); | 923 WaitUntilCompleted(); |
| 955 EXPECT_FALSE(consumer()->registration_id().empty()); | 924 EXPECT_FALSE(consumer()->registration_id().empty()); |
| 956 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 925 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 957 | 926 |
| 958 // The registration info should be cached. | 927 // The registration info should be cached. |
| 959 EXPECT_TRUE(consumer()->ExistsCachedRegistrationInfo()); | 928 EXPECT_TRUE(consumer()->ExistsCachedRegistrationInfo()); |
| 960 | 929 |
| 961 // The registration info should be persisted. | 930 // The registration info should be persisted. |
| 962 EXPECT_TRUE(consumer()->HasPersistedRegistrationInfo(extension->id())); | 931 EXPECT_TRUE(consumer()->HasPersistedRegistrationInfo(extension->id())); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1090 | 1059 |
| 1091 Profile* profile2() const { return consumer2_->profile(); } | 1060 Profile* profile2() const { return consumer2_->profile(); } |
| 1092 GCMProfileServiceTestConsumer* consumer2() const { return consumer2_.get(); } | 1061 GCMProfileServiceTestConsumer* consumer2() const { return consumer2_.get(); } |
| 1093 | 1062 |
| 1094 protected: | 1063 protected: |
| 1095 scoped_ptr<GCMProfileServiceTestConsumer> consumer2_; | 1064 scoped_ptr<GCMProfileServiceTestConsumer> consumer2_; |
| 1096 }; | 1065 }; |
| 1097 | 1066 |
| 1098 TEST_F(GCMProfileServiceMultiProfileTest, Register) { | 1067 TEST_F(GCMProfileServiceMultiProfileTest, Register) { |
| 1099 // Register an app. | 1068 // Register an app. |
| 1100 std::vector<std::string> sender_ids; | 1069 consumer()->Register(kTestingAppId, "sender1"); |
| 1101 sender_ids.push_back("sender1"); | |
| 1102 consumer()->Register(kTestingAppId, sender_ids); | |
| 1103 | 1070 |
| 1104 // Register the same app in a different profile. | 1071 // Register the same app in a different profile. |
| 1105 std::vector<std::string> sender_ids2; | 1072 consumer2()->Register(kTestingAppId, "sender2"); |
| 1106 sender_ids2.push_back("foo"); | |
| 1107 sender_ids2.push_back("bar"); | |
| 1108 consumer2()->Register(kTestingAppId, sender_ids2); | |
| 1109 | 1073 |
| 1110 WaitUntilCompleted(); | 1074 WaitUntilCompleted(); |
| 1111 WaitUntilCompleted(); | 1075 WaitUntilCompleted(); |
| 1112 | 1076 |
| 1113 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids), | 1077 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderId("sender1"), |
| 1114 consumer()->registration_id()); | 1078 consumer()->registration_id()); |
| 1115 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 1079 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 1116 | 1080 |
| 1117 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids2), | 1081 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderId("sender2"), |
| 1118 consumer2()->registration_id()); | 1082 consumer2()->registration_id()); |
| 1119 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 1083 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 1120 | 1084 |
| 1121 // Register a different app in a different profile. | 1085 // Register a different app in a different profile. |
| 1122 std::vector<std::string> sender_ids3; | 1086 consumer2()->Register(kTestingAppId2, "sender3"); |
| 1123 sender_ids3.push_back("sender1"); | |
| 1124 sender_ids3.push_back("sender2"); | |
| 1125 sender_ids3.push_back("sender3"); | |
| 1126 consumer2()->Register(kTestingAppId2, sender_ids3); | |
| 1127 | 1087 |
| 1128 WaitUntilCompleted(); | 1088 WaitUntilCompleted(); |
| 1129 | 1089 |
| 1130 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids3), | 1090 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderId("sender3"), |
| 1131 consumer2()->registration_id()); | 1091 consumer2()->registration_id()); |
| 1132 EXPECT_EQ(GCMClient::SUCCESS, consumer2()->registration_result()); | 1092 EXPECT_EQ(GCMClient::SUCCESS, consumer2()->registration_result()); |
| 1133 } | 1093 } |
| 1134 | 1094 |
| 1135 TEST_F(GCMProfileServiceMultiProfileTest, Send) { | 1095 TEST_F(GCMProfileServiceMultiProfileTest, Send) { |
| 1136 // Send a message from one app in one profile. | 1096 // Send a message from one app in one profile. |
| 1137 GCMClient::OutgoingMessage message; | 1097 GCMClient::OutgoingMessage message; |
| 1138 message.id = "1"; | 1098 message.id = "1"; |
| 1139 message.data["key1"] = "value1"; | 1099 message.data["key1"] = "value1"; |
| 1140 message.data["key2"] = "value2"; | 1100 message.data["key2"] = "value2"; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1212 // 3) Receive a message to an app in profile1 and receive a message for each of | 1172 // 3) Receive a message to an app in profile1 and receive a message for each of |
| 1213 // two apps in profile2; | 1173 // two apps in profile2; |
| 1214 // 4) Send a message foe ach of two apps in profile2; | 1174 // 4) Send a message foe ach of two apps in profile2; |
| 1215 // 5) Sign out of profile1. | 1175 // 5) Sign out of profile1. |
| 1216 // 6) Register/send stops working for profile1; | 1176 // 6) Register/send stops working for profile1; |
| 1217 // 7) The app in profile2 could still receive these events; | 1177 // 7) The app in profile2 could still receive these events; |
| 1218 // 8) Sign into profile1 with a different user. | 1178 // 8) Sign into profile1 with a different user. |
| 1219 // 9) The message to the new signed-in user will be routed. | 1179 // 9) The message to the new signed-in user will be routed. |
| 1220 TEST_F(GCMProfileServiceMultiProfileTest, Combined) { | 1180 TEST_F(GCMProfileServiceMultiProfileTest, Combined) { |
| 1221 // Register an app. | 1181 // Register an app. |
| 1222 std::vector<std::string> sender_ids; | 1182 consumer()->Register(kTestingAppId, "sender1"); |
| 1223 sender_ids.push_back("sender1"); | |
| 1224 consumer()->Register(kTestingAppId, sender_ids); | |
| 1225 | 1183 |
| 1226 // Register the same app in a different profile. | 1184 // Register the same app in a different profile. |
| 1227 std::vector<std::string> sender_ids2; | 1185 consumer2()->Register(kTestingAppId, "sender2"); |
| 1228 sender_ids2.push_back("foo"); | |
| 1229 sender_ids2.push_back("bar"); | |
| 1230 consumer2()->Register(kTestingAppId, sender_ids2); | |
| 1231 | 1186 |
| 1232 // Register a different app in a different profile. | 1187 // Register a different app in a different profile. |
| 1233 std::vector<std::string> sender_ids3; | 1188 consumer2()->Register(kTestingAppId2, "sender3"); |
| 1234 sender_ids3.push_back("sender1"); | |
| 1235 sender_ids3.push_back("sender2"); | |
| 1236 sender_ids3.push_back("sender3"); | |
| 1237 consumer2()->Register(kTestingAppId2, sender_ids3); | |
| 1238 | 1189 |
| 1239 WaitUntilCompleted(); | 1190 WaitUntilCompleted(); |
| 1240 WaitUntilCompleted(); | 1191 WaitUntilCompleted(); |
| 1241 WaitUntilCompleted(); | 1192 WaitUntilCompleted(); |
| 1242 | 1193 |
| 1243 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids), | 1194 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderId("sender1"), |
| 1244 consumer()->registration_id()); | 1195 consumer()->registration_id()); |
| 1245 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 1196 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 1246 | 1197 |
| 1247 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids3), | 1198 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderId("sender3"), |
| 1248 consumer2()->registration_id()); | 1199 consumer2()->registration_id()); |
| 1249 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 1200 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 1250 | 1201 |
| 1251 // Send a message from one profile. | 1202 // Send a message from one profile. |
| 1252 GCMClient::OutgoingMessage out_message; | 1203 GCMClient::OutgoingMessage out_message; |
| 1253 out_message.id = "1"; | 1204 out_message.id = "1"; |
| 1254 out_message.data["out1"] = "out_data1"; | 1205 out_message.data["out1"] = "out_data1"; |
| 1255 out_message.data["out1_2"] = "out_data1_2"; | 1206 out_message.data["out1_2"] = "out_data1_2"; |
| 1256 consumer()->Send(kTestingAppId, kUserId, out_message); | 1207 consumer()->Send(kTestingAppId, kUserId, out_message); |
| 1257 | 1208 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1322 WaitUntilCompleted(); | 1273 WaitUntilCompleted(); |
| 1323 | 1274 |
| 1324 EXPECT_EQ(consumer2()->send_message_id(), out_message3.id); | 1275 EXPECT_EQ(consumer2()->send_message_id(), out_message3.id); |
| 1325 EXPECT_EQ(GCMClient::SUCCESS, consumer2()->send_result()); | 1276 EXPECT_EQ(GCMClient::SUCCESS, consumer2()->send_result()); |
| 1326 | 1277 |
| 1327 // Sign out of one profile. | 1278 // Sign out of one profile. |
| 1328 consumer()->SignOut(); | 1279 consumer()->SignOut(); |
| 1329 | 1280 |
| 1330 // Register/send stops working for signed-out profile. | 1281 // Register/send stops working for signed-out profile. |
| 1331 consumer()->gcm_event_router()->clear_results(); | 1282 consumer()->gcm_event_router()->clear_results(); |
| 1332 consumer()->Register(kTestingAppId, sender_ids); | 1283 consumer()->Register(kTestingAppId, "sender1"); |
| 1333 EXPECT_TRUE(consumer()->registration_id().empty()); | 1284 EXPECT_TRUE(consumer()->registration_id().empty()); |
| 1334 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, consumer()->registration_result()); | 1285 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, consumer()->registration_result()); |
| 1335 | 1286 |
| 1336 consumer()->gcm_event_router()->clear_results(); | 1287 consumer()->gcm_event_router()->clear_results(); |
| 1337 consumer()->Send(kTestingAppId2, kUserId2, out_message3); | 1288 consumer()->Send(kTestingAppId2, kUserId2, out_message3); |
| 1338 EXPECT_TRUE(consumer()->send_message_id().empty()); | 1289 EXPECT_TRUE(consumer()->send_message_id().empty()); |
| 1339 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, consumer()->send_result()); | 1290 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, consumer()->send_result()); |
| 1340 | 1291 |
| 1341 // Deleted messages event will go through for another signed-in profile. | 1292 // Deleted messages event will go through for another signed-in profile. |
| 1342 consumer2()->GetGCMClient()->DeleteMessages(kTestingAppId2); | 1293 consumer2()->GetGCMClient()->DeleteMessages(kTestingAppId2); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 consumer()->gcm_event_router()->clear_results(); | 1330 consumer()->gcm_event_router()->clear_results(); |
| 1380 WaitUntilCompleted(); | 1331 WaitUntilCompleted(); |
| 1381 | 1332 |
| 1382 EXPECT_EQ(FakeGCMEventRouter::MESSAGE_EVENT, | 1333 EXPECT_EQ(FakeGCMEventRouter::MESSAGE_EVENT, |
| 1383 consumer()->gcm_event_router()->received_event()); | 1334 consumer()->gcm_event_router()->received_event()); |
| 1384 EXPECT_TRUE( | 1335 EXPECT_TRUE( |
| 1385 in_message5.data == consumer()->gcm_event_router()->message().data); | 1336 in_message5.data == consumer()->gcm_event_router()->message().data); |
| 1386 } | 1337 } |
| 1387 | 1338 |
| 1388 } // namespace gcm | 1339 } // namespace gcm |
| OLD | NEW |