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

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

Issue 683913005: [GCM] Support registration before unregistration finishes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add more comments Created 6 years, 1 month 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
« no previous file with comments | « components/gcm_driver/gcm_driver.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_driver_desktop.h" 5 #include "components/gcm_driver/gcm_driver_desktop.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 818
819 Unregister(kTestAppID1, GCMDriverTest::WAIT); 819 Unregister(kTestAppID1, GCMDriverTest::WAIT);
820 820
821 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result()); 821 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result());
822 } 822 }
823 823
824 TEST_F(GCMDriverFunctionalTest, UnregisterWhenAsyncOperationPending) { 824 TEST_F(GCMDriverFunctionalTest, UnregisterWhenAsyncOperationPending) {
825 std::vector<std::string> sender_ids; 825 std::vector<std::string> sender_ids;
826 sender_ids.push_back("sender1"); 826 sender_ids.push_back("sender1");
827 // First start registration without waiting for it to complete. 827 // First start registration without waiting for it to complete.
828 Register(kTestAppID1, 828 Register(kTestAppID1, sender_ids, GCMDriverTest::DO_NOT_WAIT);
829 sender_ids,
830 GCMDriverTest::DO_NOT_WAIT);
831 829
832 // Test that unregistration fails with async operation pending when there is a 830 // Test that unregistration fails with async operation pending when there is a
833 // registration already in progress. 831 // registration already in progress.
834 Unregister(kTestAppID1, GCMDriverTest::WAIT); 832 Unregister(kTestAppID1, GCMDriverTest::WAIT);
835 EXPECT_EQ(GCMClient::ASYNC_OPERATION_PENDING, 833 EXPECT_EQ(GCMClient::ASYNC_OPERATION_PENDING,
836 unregistration_result()); 834 unregistration_result());
837 835
838 // Complete the unregistration. 836 // Complete the unregistration.
839 WaitForAsyncOperation(); 837 WaitForAsyncOperation();
840 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); 838 EXPECT_EQ(GCMClient::SUCCESS, registration_result());
(...skipping 11 matching lines...) Expand all
852 850
853 // Complete unregistration. 851 // Complete unregistration.
854 WaitForAsyncOperation(); 852 WaitForAsyncOperation();
855 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result()); 853 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result());
856 } 854 }
857 855
858 TEST_F(GCMDriverFunctionalTest, RegisterWhenAsyncOperationPending) { 856 TEST_F(GCMDriverFunctionalTest, RegisterWhenAsyncOperationPending) {
859 std::vector<std::string> sender_ids; 857 std::vector<std::string> sender_ids;
860 sender_ids.push_back("sender1"); 858 sender_ids.push_back("sender1");
861 // First start registration without waiting for it to complete. 859 // First start registration without waiting for it to complete.
862 Register(kTestAppID1, 860 Register(kTestAppID1, sender_ids, GCMDriverTest::DO_NOT_WAIT);
863 sender_ids,
864 GCMDriverTest::DO_NOT_WAIT);
865 861
866 // Test that registration fails with async operation pending when there is a 862 // Test that registration fails with async operation pending when there is a
867 // registration already in progress. 863 // registration already in progress.
868 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT); 864 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT);
869 EXPECT_EQ(GCMClient::ASYNC_OPERATION_PENDING, 865 EXPECT_EQ(GCMClient::ASYNC_OPERATION_PENDING,
870 registration_result()); 866 registration_result());
871 ClearResults(); 867 ClearResults();
872 868
873 // Complete the registration. 869 // Complete the registration.
874 WaitForAsyncOperation(); 870 WaitForAsyncOperation();
875 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); 871 EXPECT_EQ(GCMClient::SUCCESS, registration_result());
872 }
876 873
877 // Start unregistration without waiting for it to complete. This time no async 874 TEST_F(GCMDriverFunctionalTest, RegisterAfterUnfinishedUnregister) {
878 // operation is pending. 875 // Register and wait for it to complete.
876 std::vector<std::string> sender_ids;
877 sender_ids.push_back("sender1");
878 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT);
879 EXPECT_EQ(GCMClient::SUCCESS, registration_result());
880 EXPECT_EQ(GetGCMClient()->GetRegistrationIdFromSenderIds(sender_ids),
881 registration_id());
882
883 // Clears the results the would be set by the Register callback in preparation
884 // to call register 2nd time.
885 ClearResults();
886
887 // Start unregistration without waiting for it to complete.
879 Unregister(kTestAppID1, GCMDriverTest::DO_NOT_WAIT); 888 Unregister(kTestAppID1, GCMDriverTest::DO_NOT_WAIT);
880 889
881 // Test that registration fails with async operation pending when there is an 890 // Register immeidately after unregistration is not completed.
882 // unregistration already in progress. 891 sender_ids.push_back("sender2");
883 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT); 892 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT);
884 EXPECT_EQ(GCMClient::ASYNC_OPERATION_PENDING,
885 registration_result());
886 893
887 // Complete the first unregistration expecting success. 894 // We need one more waiting since the waiting in Register is indeed for
895 // uncompleted Unregister.
888 WaitForAsyncOperation(); 896 WaitForAsyncOperation();
889 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result());
890
891 // Test that it is ok to register again after unregistration.
892 Register(kTestAppID1, sender_ids, GCMDriverTest::WAIT);
893 EXPECT_EQ(GCMClient::SUCCESS, registration_result()); 897 EXPECT_EQ(GCMClient::SUCCESS, registration_result());
898 EXPECT_EQ(GetGCMClient()->GetRegistrationIdFromSenderIds(sender_ids),
899 registration_id());
894 } 900 }
895 901
896 TEST_F(GCMDriverFunctionalTest, Send) { 902 TEST_F(GCMDriverFunctionalTest, Send) {
897 GCMClient::OutgoingMessage message; 903 GCMClient::OutgoingMessage message;
898 message.id = "1@ack"; 904 message.id = "1@ack";
899 message.data["key1"] = "value1"; 905 message.data["key1"] = "value1";
900 message.data["key2"] = "value2"; 906 message.data["key2"] = "value2";
901 Send(kTestAppID1, kUserID1, message, GCMDriverTest::WAIT); 907 Send(kTestAppID1, kUserID1, message, GCMDriverTest::WAIT);
902 908
903 EXPECT_EQ(message.id, send_message_id()); 909 EXPECT_EQ(message.id, send_message_id());
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 // After start-up, the request should still be scheduled at the expected 1244 // After start-up, the request should still be scheduled at the expected
1239 // updated interval. 1245 // updated interval.
1240 actual_delay_seconds = 1246 actual_delay_seconds =
1241 syncer()->current_request_delay_interval().InSeconds(); 1247 syncer()->current_request_delay_interval().InSeconds();
1242 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds)) 1248 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds))
1243 << "expected delay: " << expected_delay_seconds 1249 << "expected delay: " << expected_delay_seconds
1244 << " actual delay: " << actual_delay_seconds; 1250 << " actual delay: " << actual_delay_seconds;
1245 } 1251 }
1246 1252
1247 } // namespace gcm 1253 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_driver.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698