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 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 // help catch this. | 758 // help catch this. |
759 consumer()->set_gcm_client_error_simulation(GCMClientMock::FORCE_ERROR); | 759 consumer()->set_gcm_client_error_simulation(GCMClientMock::FORCE_ERROR); |
760 | 760 |
761 // Simulate start-up by recreating GCMProfileService. | 761 // Simulate start-up by recreating GCMProfileService. |
762 consumer()->CreateGCMProfileServiceInstance(); | 762 consumer()->CreateGCMProfileServiceInstance(); |
763 | 763 |
764 // Simulate start-up by reloading extension. | 764 // Simulate start-up by reloading extension. |
765 consumer()->ReloadExtension(extension); | 765 consumer()->ReloadExtension(extension); |
766 | 766 |
767 // This should read the registration info from the extension's state store. | 767 // This should read the registration info from the extension's state store. |
768 // We still need to wait since the reading from state store might happen at | |
769 // the same time. | |
770 consumer()->Register(extension->id(), sender_ids); | 768 consumer()->Register(extension->id(), sender_ids); |
771 WaitUntilCompleted(); | 769 PumpUILoop(); |
772 EXPECT_EQ(old_registration_id, consumer()->registration_id()); | 770 EXPECT_EQ(old_registration_id, consumer()->registration_id()); |
773 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 771 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
774 } | 772 } |
775 | 773 |
776 TEST_F(GCMProfileServiceSingleProfileTest, | 774 TEST_F(GCMProfileServiceSingleProfileTest, |
777 GCMClientReadyAfterReadingRegistration) { | 775 GCMClientReadyAfterReadingRegistration) { |
778 scoped_refptr<Extension> extension(consumer()->CreateExtension()); | 776 scoped_refptr<Extension> extension(consumer()->CreateExtension()); |
779 | 777 |
780 std::vector<std::string> sender_ids; | 778 std::vector<std::string> sender_ids; |
781 sender_ids.push_back("sender1"); | 779 sender_ids.push_back("sender1"); |
(...skipping 24 matching lines...) Expand all Loading... |
806 EXPECT_TRUE(consumer()->registration_id().empty()); | 804 EXPECT_TRUE(consumer()->registration_id().empty()); |
807 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, consumer()->registration_result()); | 805 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, consumer()->registration_result()); |
808 | 806 |
809 // Register operation will be invoked after GCMClient becomes ready. | 807 // Register operation will be invoked after GCMClient becomes ready. |
810 consumer()->GetGCMClient()->SetReady(); | 808 consumer()->GetGCMClient()->SetReady(); |
811 WaitUntilCompleted(); | 809 WaitUntilCompleted(); |
812 EXPECT_EQ(old_registration_id, consumer()->registration_id()); | 810 EXPECT_EQ(old_registration_id, consumer()->registration_id()); |
813 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); | 811 EXPECT_EQ(GCMClient::SUCCESS, consumer()->registration_result()); |
814 } | 812 } |
815 | 813 |
| 814 TEST_F(GCMProfileServiceSingleProfileTest, |
| 815 PersistedRegistrationInfoRemoveAfterSignOut) { |
| 816 std::vector<std::string> sender_ids; |
| 817 sender_ids.push_back("sender1"); |
| 818 consumer()->Register(kTestingAppId, sender_ids); |
| 819 WaitUntilCompleted(); |
| 820 |
| 821 // The app id and registration info should be persisted. |
| 822 EXPECT_TRUE(profile()->GetPrefs()->HasPrefPath(prefs::kGCMRegisteredAppIDs)); |
| 823 EXPECT_TRUE(consumer()->HasPersistedRegistrationInfo(kTestingAppId)); |
| 824 |
| 825 consumer()->SignOut(); |
| 826 PumpUILoop(); |
| 827 |
| 828 // The app id and persisted registration info should be removed. |
| 829 EXPECT_FALSE(profile()->GetPrefs()->HasPrefPath(prefs::kGCMRegisteredAppIDs)); |
| 830 EXPECT_FALSE(consumer()->HasPersistedRegistrationInfo(kTestingAppId)); |
| 831 } |
| 832 |
816 TEST_F(GCMProfileServiceSingleProfileTest, RegisterAfterSignOut) { | 833 TEST_F(GCMProfileServiceSingleProfileTest, RegisterAfterSignOut) { |
817 // This will trigger check-out. | 834 // This will trigger check-out. |
818 consumer()->SignOut(); | 835 consumer()->SignOut(); |
819 | 836 |
820 std::vector<std::string> sender_ids; | 837 std::vector<std::string> sender_ids; |
821 sender_ids.push_back("sender1"); | 838 sender_ids.push_back("sender1"); |
822 consumer()->Register(kTestingAppId, sender_ids); | 839 consumer()->Register(kTestingAppId, sender_ids); |
823 | 840 |
824 EXPECT_TRUE(consumer()->registration_id().empty()); | 841 EXPECT_TRUE(consumer()->registration_id().empty()); |
825 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, consumer()->registration_result()); | 842 EXPECT_EQ(GCMClient::NOT_SIGNED_IN, consumer()->registration_result()); |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1245 consumer()->gcm_event_router()->clear_results(); | 1262 consumer()->gcm_event_router()->clear_results(); |
1246 WaitUntilCompleted(); | 1263 WaitUntilCompleted(); |
1247 | 1264 |
1248 EXPECT_EQ(FakeGCMEventRouter::MESSAGE_EVENT, | 1265 EXPECT_EQ(FakeGCMEventRouter::MESSAGE_EVENT, |
1249 consumer()->gcm_event_router()->received_event()); | 1266 consumer()->gcm_event_router()->received_event()); |
1250 EXPECT_TRUE( | 1267 EXPECT_TRUE( |
1251 in_message5.data == consumer()->gcm_event_router()->message().data); | 1268 in_message5.data == consumer()->gcm_event_router()->message().data); |
1252 } | 1269 } |
1253 | 1270 |
1254 } // namespace gcm | 1271 } // namespace gcm |
OLD | NEW |