Chromium Code Reviews| 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::GetRegistrationIdFromSenderIds("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::GetRegistrationIdFromSenderIds("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::GetRegistrationIdFromSenderIds("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, "sedner1@error"); |
|
jianli
2014/03/03 21:29:31
nit: typo for sender
fgorski
2014/03/03 23:14:16
Done. Brilliant catch!
| |
| 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, RegisterAgainWithSameSenderIDs) { |
|
jianli
2014/03/03 21:29:31
Remove the trailing "s" from the test case name.
fgorski
2014/03/03 23:14:16
Done.
| |
| 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::GetRegistrationIdFromSenderIds("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 RegisterAgainWithDifferentSenderIDs) { |
|
jianli
2014/03/03 21:29:31
ditto.
fgorski
2014/03/03 23:14:16
Done.
| |
| 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::GetRegistrationIdFromSenderIds("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 IDs different. |
|
jianli
2014/03/03 21:29:31
IDs => ID
fgorski
2014/03/03 23:14:16
Done.
| |
| 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::GetRegistrationIdFromSenderIds("sender2"); |
| 835 | 814 |
| 836 // Calling register 2nd time with the different sender IDs will get back a new | 815 // Calling register 2nd time with the different sender IDs 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1075 | 1044 |
| 1076 Profile* profile2() const { return consumer2_->profile(); } | 1045 Profile* profile2() const { return consumer2_->profile(); } |
| 1077 GCMProfileServiceTestConsumer* consumer2() const { return consumer2_.get(); } | 1046 GCMProfileServiceTestConsumer* consumer2() const { return consumer2_.get(); } |
| 1078 | 1047 |
| 1079 protected: | 1048 protected: |
| 1080 scoped_ptr<GCMProfileServiceTestConsumer> consumer2_; | 1049 scoped_ptr<GCMProfileServiceTestConsumer> consumer2_; |
| 1081 }; | 1050 }; |
| 1082 | 1051 |
| 1083 TEST_F(GCMProfileServiceMultiProfileTest, Register) { | 1052 TEST_F(GCMProfileServiceMultiProfileTest, Register) { |
| 1084 // Register an app. | 1053 // Register an app. |
| 1085 std::vector<std::string> sender_ids; | 1054 consumer()->Register(kTestingAppId, "sender1"); |
| 1086 sender_ids.push_back("sender1"); | |
| 1087 consumer()->Register(kTestingAppId, sender_ids); | |
| 1088 | 1055 |
| 1089 // Register the same app in a different profile. | 1056 // Register the same app in a different profile. |
| 1090 std::vector<std::string> sender_ids2; | 1057 consumer2()->Register(kTestingAppId, "sender2"); |
| 1091 sender_ids2.push_back("foo"); | |
| 1092 sender_ids2.push_back("bar"); | |
| 1093 consumer2()->Register(kTestingAppId, sender_ids2); | |
| 1094 | 1058 |
| 1095 WaitUntilCompleted(); | 1059 WaitUntilCompleted(); |
| 1096 WaitUntilCompleted(); | 1060 WaitUntilCompleted(); |
| 1097 | 1061 |
| 1098 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids), | 1062 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds("sender1"), |
| 1099 consumer()->registration_id()); | 1063 consumer()->registration_id()); |
| 1100 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 1064 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 1101 | 1065 |
| 1102 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids2), | 1066 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds("sender2"), |
| 1103 consumer2()->registration_id()); | 1067 consumer2()->registration_id()); |
| 1104 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 1068 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 1105 | 1069 |
| 1106 // Register a different app in a different profile. | 1070 // Register a different app in a different profile. |
| 1107 std::vector<std::string> sender_ids3; | 1071 consumer2()->Register(kTestingAppId2, "sender3"); |
| 1108 sender_ids3.push_back("sender1"); | |
| 1109 sender_ids3.push_back("sender2"); | |
| 1110 sender_ids3.push_back("sender3"); | |
| 1111 consumer2()->Register(kTestingAppId2, sender_ids3); | |
| 1112 | 1072 |
| 1113 WaitUntilCompleted(); | 1073 WaitUntilCompleted(); |
| 1114 | 1074 |
| 1115 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids3), | 1075 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds("sender3"), |
| 1116 consumer2()->registration_id()); | 1076 consumer2()->registration_id()); |
| 1117 EXPECT_EQ(GCMClient::SUCCESS, consumer2()->registration_result()); | 1077 EXPECT_EQ(GCMClient::SUCCESS, consumer2()->registration_result()); |
| 1118 } | 1078 } |
| 1119 | 1079 |
| 1120 TEST_F(GCMProfileServiceMultiProfileTest, Send) { | 1080 TEST_F(GCMProfileServiceMultiProfileTest, Send) { |
| 1121 // Send a message from one app in one profile. | 1081 // Send a message from one app in one profile. |
| 1122 GCMClient::OutgoingMessage message; | 1082 GCMClient::OutgoingMessage message; |
| 1123 message.id = "1"; | 1083 message.id = "1"; |
| 1124 message.data["key1"] = "value1"; | 1084 message.data["key1"] = "value1"; |
| 1125 message.data["key2"] = "value2"; | 1085 message.data["key2"] = "value2"; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1197 // 3) Receive a message to an app in profile1 and receive a message for each of | 1157 // 3) Receive a message to an app in profile1 and receive a message for each of |
| 1198 // two apps in profile2; | 1158 // two apps in profile2; |
| 1199 // 4) Send a message foe ach of two apps in profile2; | 1159 // 4) Send a message foe ach of two apps in profile2; |
| 1200 // 5) Sign out of profile1. | 1160 // 5) Sign out of profile1. |
| 1201 // 6) Register/send stops working for profile1; | 1161 // 6) Register/send stops working for profile1; |
| 1202 // 7) The app in profile2 could still receive these events; | 1162 // 7) The app in profile2 could still receive these events; |
| 1203 // 8) Sign into profile1 with a different user. | 1163 // 8) Sign into profile1 with a different user. |
| 1204 // 9) The message to the new signed-in user will be routed. | 1164 // 9) The message to the new signed-in user will be routed. |
| 1205 TEST_F(GCMProfileServiceMultiProfileTest, Combined) { | 1165 TEST_F(GCMProfileServiceMultiProfileTest, Combined) { |
| 1206 // Register an app. | 1166 // Register an app. |
| 1207 std::vector<std::string> sender_ids; | 1167 consumer()->Register(kTestingAppId, "sender1"); |
| 1208 sender_ids.push_back("sender1"); | |
| 1209 consumer()->Register(kTestingAppId, sender_ids); | |
| 1210 | 1168 |
| 1211 // Register the same app in a different profile. | 1169 // Register the same app in a different profile. |
| 1212 std::vector<std::string> sender_ids2; | 1170 consumer2()->Register(kTestingAppId, "sender2"); |
| 1213 sender_ids2.push_back("foo"); | |
| 1214 sender_ids2.push_back("bar"); | |
| 1215 consumer2()->Register(kTestingAppId, sender_ids2); | |
| 1216 | 1171 |
| 1217 // Register a different app in a different profile. | 1172 // Register a different app in a different profile. |
| 1218 std::vector<std::string> sender_ids3; | 1173 consumer2()->Register(kTestingAppId2, "sender3"); |
| 1219 sender_ids3.push_back("sender1"); | |
| 1220 sender_ids3.push_back("sender2"); | |
| 1221 sender_ids3.push_back("sender3"); | |
| 1222 consumer2()->Register(kTestingAppId2, sender_ids3); | |
| 1223 | 1174 |
| 1224 WaitUntilCompleted(); | 1175 WaitUntilCompleted(); |
| 1225 WaitUntilCompleted(); | 1176 WaitUntilCompleted(); |
| 1226 WaitUntilCompleted(); | 1177 WaitUntilCompleted(); |
| 1227 | 1178 |
| 1228 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids), | 1179 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds("sender1"), |
| 1229 consumer()->registration_id()); | 1180 consumer()->registration_id()); |
| 1230 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 1181 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 1231 | 1182 |
| 1232 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds(sender_ids3), | 1183 EXPECT_EQ(GCMClientMock::GetRegistrationIdFromSenderIds("sender3"), |
| 1233 consumer2()->registration_id()); | 1184 consumer2()->registration_id()); |
| 1234 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 1185 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
| 1235 | 1186 |
| 1236 // Send a message from one profile. | 1187 // Send a message from one profile. |
| 1237 GCMClient::OutgoingMessage out_message; | 1188 GCMClient::OutgoingMessage out_message; |
| 1238 out_message.id = "1"; | 1189 out_message.id = "1"; |
| 1239 out_message.data["out1"] = "out_data1"; | 1190 out_message.data["out1"] = "out_data1"; |
| 1240 out_message.data["out1_2"] = "out_data1_2"; | 1191 out_message.data["out1_2"] = "out_data1_2"; |
| 1241 consumer()->Send(kTestingAppId, kUserId, out_message); | 1192 consumer()->Send(kTestingAppId, kUserId, out_message); |
| 1242 | 1193 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1307 WaitUntilCompleted(); | 1258 WaitUntilCompleted(); |
| 1308 | 1259 |
| 1309 EXPECT_EQ(consumer2()->send_message_id(), out_message3.id); | 1260 EXPECT_EQ(consumer2()->send_message_id(), out_message3.id); |
| 1310 EXPECT_EQ(GCMClient::SUCCESS, consumer2()->send_result()); | 1261 EXPECT_EQ(GCMClient::SUCCESS, consumer2()->send_result()); |
| 1311 | 1262 |
| 1312 // Sign out of one profile. | 1263 // Sign out of one profile. |
| 1313 consumer()->SignOut(); | 1264 consumer()->SignOut(); |
| 1314 | 1265 |
| 1315 // Register/send stops working for signed-out profile. | 1266 // Register/send stops working for signed-out profile. |
| 1316 consumer()->gcm_event_router()->clear_results(); | 1267 consumer()->gcm_event_router()->clear_results(); |
| 1317 consumer()->Register(kTestingAppId, sender_ids); | 1268 consumer()->Register(kTestingAppId, "sender1"); |
| 1318 EXPECT_TRUE(consumer()->registration_id().empty()); | 1269 EXPECT_TRUE(consumer()->registration_id().empty()); |
| 1319 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, consumer()->registration_result()); | 1270 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, consumer()->registration_result()); |
| 1320 | 1271 |
| 1321 consumer()->gcm_event_router()->clear_results(); | 1272 consumer()->gcm_event_router()->clear_results(); |
| 1322 consumer()->Send(kTestingAppId2, kUserId2, out_message3); | 1273 consumer()->Send(kTestingAppId2, kUserId2, out_message3); |
| 1323 EXPECT_TRUE(consumer()->send_message_id().empty()); | 1274 EXPECT_TRUE(consumer()->send_message_id().empty()); |
| 1324 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, consumer()->send_result()); | 1275 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, consumer()->send_result()); |
| 1325 | 1276 |
| 1326 // Deleted messages event will go through for another signed-in profile. | 1277 // Deleted messages event will go through for another signed-in profile. |
| 1327 consumer2()->GetGCMClient()->DeleteMessages(kTestingAppId2); | 1278 consumer2()->GetGCMClient()->DeleteMessages(kTestingAppId2); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1364 consumer()->gcm_event_router()->clear_results(); | 1315 consumer()->gcm_event_router()->clear_results(); |
| 1365 WaitUntilCompleted(); | 1316 WaitUntilCompleted(); |
| 1366 | 1317 |
| 1367 EXPECT_EQ(FakeGCMEventRouter::MESSAGE_EVENT, | 1318 EXPECT_EQ(FakeGCMEventRouter::MESSAGE_EVENT, |
| 1368 consumer()->gcm_event_router()->received_event()); | 1319 consumer()->gcm_event_router()->received_event()); |
| 1369 EXPECT_TRUE( | 1320 EXPECT_TRUE( |
| 1370 in_message5.data == consumer()->gcm_event_router()->message().data); | 1321 in_message5.data == consumer()->gcm_event_router()->message().data); |
| 1371 } | 1322 } |
| 1372 | 1323 |
| 1373 } // namespace gcm | 1324 } // namespace gcm |
| OLD | NEW |