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

Side by Side Diff: google_apis/gcm/engine/mcs_client_unittest.cc

Issue 1124783002: [GCM] Wiring heartbeat interval calls to GCMDriver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@store-heartbeat-gcm
Patch Set: Addressing final feedback and fixing formatting Created 5 years, 7 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
« no previous file with comments | « google_apis/gcm/engine/mcs_client.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "google_apis/gcm/engine/mcs_client.h" 5 #include "google_apis/gcm/engine/mcs_client.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/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 public: 106 public:
107 MCSClientTest(); 107 MCSClientTest();
108 ~MCSClientTest() override; 108 ~MCSClientTest() override;
109 109
110 void SetUp() override; 110 void SetUp() override;
111 111
112 void BuildMCSClient(); 112 void BuildMCSClient();
113 void InitializeClient(); 113 void InitializeClient();
114 void StoreCredentials(); 114 void StoreCredentials();
115 void LoginClient(const std::vector<std::string>& acknowledged_ids); 115 void LoginClient(const std::vector<std::string>& acknowledged_ids);
116 void LoginClientWithHeartbeat(
117 const std::vector<std::string>& acknowledged_ids,
118 int heartbeat_interval_ms);
116 void AddExpectedLoginRequest(const std::vector<std::string>& acknowledged_ids, 119 void AddExpectedLoginRequest(const std::vector<std::string>& acknowledged_ids,
117 int custom_heartbeat_interval); 120 int heartbeat_interval_ms);
118 121
119 base::SimpleTestClock* clock() { return &clock_; } 122 base::SimpleTestClock* clock() { return &clock_; }
120 TestMCSClient* mcs_client() const { return mcs_client_.get(); } 123 TestMCSClient* mcs_client() const { return mcs_client_.get(); }
121 FakeConnectionFactory* connection_factory() { 124 FakeConnectionFactory* connection_factory() {
122 return &connection_factory_; 125 return &connection_factory_;
123 } 126 }
124 bool init_success() const { return init_success_; } 127 bool init_success() const { return init_success_; }
125 uint64 restored_android_id() const { return restored_android_id_; } 128 uint64 restored_android_id() const { return restored_android_id_; }
126 uint64 restored_security_token() const { return restored_security_token_; } 129 uint64 restored_security_token() const { return restored_security_token_; }
127 MCSMessage* received_message() const { return received_message_.get(); } 130 MCSMessage* received_message() const { return received_message_.get(); }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 base::Unretained(this)), 205 base::Unretained(this)),
203 base::Bind(&MCSClientTest::MessageReceivedCallback, 206 base::Bind(&MCSClientTest::MessageReceivedCallback,
204 base::Unretained(this)), 207 base::Unretained(this)),
205 base::Bind(&MCSClientTest::MessageSentCallback, base::Unretained(this)))); 208 base::Bind(&MCSClientTest::MessageSentCallback, base::Unretained(this))));
206 run_loop_->RunUntilIdle(); 209 run_loop_->RunUntilIdle();
207 run_loop_.reset(new base::RunLoop()); 210 run_loop_.reset(new base::RunLoop());
208 } 211 }
209 212
210 void MCSClientTest::LoginClient( 213 void MCSClientTest::LoginClient(
211 const std::vector<std::string>& acknowledged_ids) { 214 const std::vector<std::string>& acknowledged_ids) {
212 AddExpectedLoginRequest(acknowledged_ids, 0); 215 LoginClientWithHeartbeat(acknowledged_ids, 0);
216 }
217
218 void MCSClientTest::LoginClientWithHeartbeat(
219 const std::vector<std::string>& acknowledged_ids,
220 int heartbeat_interval_ms) {
221 AddExpectedLoginRequest(acknowledged_ids, heartbeat_interval_ms);
213 mcs_client_->Login(kAndroidId, kSecurityToken); 222 mcs_client_->Login(kAndroidId, kSecurityToken);
214 run_loop_->Run(); 223 run_loop_->Run();
215 run_loop_.reset(new base::RunLoop()); 224 run_loop_.reset(new base::RunLoop());
216 } 225 }
217 226
218 void MCSClientTest::AddExpectedLoginRequest( 227 void MCSClientTest::AddExpectedLoginRequest(
219 const std::vector<std::string>& acknowledged_ids, 228 const std::vector<std::string>& acknowledged_ids,
220 int custom_heartbeat_interval) { 229 int heartbeat_interval_ms) {
221 scoped_ptr<mcs_proto::LoginRequest> login_request = 230 scoped_ptr<mcs_proto::LoginRequest> login_request =
222 BuildLoginRequest(kAndroidId, kSecurityToken, ""); 231 BuildLoginRequest(kAndroidId, kSecurityToken, "");
223 for (size_t i = 0; i < acknowledged_ids.size(); ++i) 232 for (size_t i = 0; i < acknowledged_ids.size(); ++i)
224 login_request->add_received_persistent_id(acknowledged_ids[i]); 233 login_request->add_received_persistent_id(acknowledged_ids[i]);
225 if (custom_heartbeat_interval) { 234 if (heartbeat_interval_ms) {
226 mcs_proto::Setting* setting = login_request->add_setting(); 235 mcs_proto::Setting* setting = login_request->add_setting();
227 setting->set_name("hbping"); 236 setting->set_name("hbping");
228 setting->set_value(base::IntToString(custom_heartbeat_interval)); 237 setting->set_value(base::IntToString(heartbeat_interval_ms));
229 } 238 }
230 GetFakeHandler()->ExpectOutgoingMessage( 239 GetFakeHandler()->ExpectOutgoingMessage(
231 MCSMessage(kLoginRequestTag, login_request.Pass())); 240 MCSMessage(kLoginRequestTag, login_request.Pass()));
232 } 241 }
233 242
234 void MCSClientTest::StoreCredentials() { 243 void MCSClientTest::StoreCredentials() {
235 gcm_store_->SetDeviceCredentials( 244 gcm_store_->SetDeviceCredentials(
236 kAndroidId, kSecurityToken, 245 kAndroidId, kSecurityToken,
237 base::Bind(&MCSClientTest::SetDeviceCredentialsCallback, 246 base::Bind(&MCSClientTest::SetDeviceCredentialsCallback,
238 base::Unretained(this))); 247 base::Unretained(this)));
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 "token", 900 "token",
892 1)); 901 1));
893 mcs_client()->SendMessage(message2); 902 mcs_client()->SendMessage(message2);
894 903
895 LoginClient(std::vector<std::string>()); 904 LoginClient(std::vector<std::string>());
896 GetFakeHandler()->ExpectOutgoingMessage(message); 905 GetFakeHandler()->ExpectOutgoingMessage(message);
897 GetFakeHandler()->ExpectOutgoingMessage(message2); 906 GetFakeHandler()->ExpectOutgoingMessage(message2);
898 PumpLoop(); 907 PumpLoop();
899 } 908 }
900 909
910 // Test case for setting a custom heartbeat interval, when it is too short.
911 // Covers both connection restart and storing of custom intervals.
912 TEST_F(MCSClientTest, CustomHeartbeatIntervalTooShort) {
913 BuildMCSClient();
914 InitializeClient();
915 LoginClient(std::vector<std::string>());
916 PumpLoop();
917 StoreCredentials();
918
919 HeartbeatManager* hb_manager = mcs_client()->GetHeartbeatManagerForTesting();
920 // By default custom client interval is not set.
921 EXPECT_FALSE(hb_manager->HasClientHeartbeatInterval());
922
923 const std::string component_1 = "component1";
924 int interval_ms = 30 * 1000; // 30 seconds, too low.
925 mcs_client()->AddHeartbeatInterval(component_1, interval_ms);
926 // Setting was too low so it was ignored.
927 EXPECT_FALSE(hb_manager->HasClientHeartbeatInterval());
928
929 // Restore and check again to make sure that nothing was set in store.
930 BuildMCSClient();
931 InitializeClient();
932 LoginClientWithHeartbeat(std::vector<std::string>(), 0);
933 PumpLoop();
934
935 hb_manager = mcs_client()->GetHeartbeatManagerForTesting();
936 EXPECT_FALSE(hb_manager->HasClientHeartbeatInterval());
937 }
938
939 // Test case for setting a custom heartbeat interval, when it is too long.
940 // Covers both connection restart and storing of custom intervals.
941 TEST_F(MCSClientTest, CustomHeartbeatIntervalTooLong) {
942 BuildMCSClient();
943 InitializeClient();
944 LoginClient(std::vector<std::string>());
945 PumpLoop();
946 StoreCredentials();
947
948 HeartbeatManager* hb_manager = mcs_client()->GetHeartbeatManagerForTesting();
949
950 const std::string component_1 = "component1";
951 int interval_ms = 60 * 60 * 1000; // 1 hour, too high.
952 mcs_client()->AddHeartbeatInterval(component_1, interval_ms);
953 // Setting was too high, again it was ignored.
954 EXPECT_FALSE(hb_manager->HasClientHeartbeatInterval());
955
956 // Restore and check again to make sure that nothing was set in store.
957 BuildMCSClient();
958 InitializeClient();
959 LoginClientWithHeartbeat(std::vector<std::string>(), 0);
960 PumpLoop();
961
962 // Setting was too high, again it was ignored.
963 hb_manager = mcs_client()->GetHeartbeatManagerForTesting();
964 EXPECT_FALSE(hb_manager->HasClientHeartbeatInterval());
965 }
966
901 // Tests adding and removing custom heartbeat interval. 967 // Tests adding and removing custom heartbeat interval.
902 TEST_F(MCSClientTest, CustomHeartbeatInterval) { 968 // Covers both connection restart and storing of custom intervals.
903 BuildMCSClient(); 969 TEST_F(MCSClientTest, CustomHeartbeatIntervalSingleInterval) {
904 InitializeClient(); 970 BuildMCSClient();
905 LoginClient(std::vector<std::string>()); 971 InitializeClient();
906 972 LoginClient(std::vector<std::string>());
907 TestConnectionListener test_connection_listener; 973 PumpLoop();
908 connection_factory()->SetConnectionListener(&test_connection_listener); 974 StoreCredentials();
909 975
910 HeartbeatManager& hb_manager = mcs_client()->GetHeartbeatManagerForTesting(); 976 TestConnectionListener test_connection_listener;
911 // By default custom client interval is not set. 977 connection_factory()->SetConnectionListener(&test_connection_listener);
912 EXPECT_FALSE(hb_manager.HasClientHeartbeatInterval()); 978
913 979 HeartbeatManager* hb_manager = mcs_client()->GetHeartbeatManagerForTesting();
914 const std::string component_1 = "component1"; 980
915 int interval_ms = 30 * 1000; // 30 seconds, too low. 981 const std::string component_1 = "component1";
916 mcs_client()->AddHeartbeatInterval(component_1, interval_ms); 982 int interval_ms = 5 * 60 * 1000; // 5 minutes. A valid setting.
917 // Setting was too low so it was ignored. 983
918 EXPECT_FALSE(hb_manager.HasClientHeartbeatInterval()); 984 AddExpectedLoginRequest(std::vector<std::string>(), interval_ms);
919 985 mcs_client()->AddHeartbeatInterval(component_1, interval_ms);
920 interval_ms = 60 * 60 * 1000; // 1 hour, too high. 986 PumpLoop();
921 mcs_client()->AddHeartbeatInterval(component_1, interval_ms); 987
922 // Setting was too high, again it was ignored. 988 // Interval was OK. HearbeatManager should get that setting now.
923 EXPECT_FALSE(hb_manager.HasClientHeartbeatInterval()); 989 EXPECT_TRUE(hb_manager->HasClientHeartbeatInterval());
924 990 EXPECT_EQ(interval_ms, hb_manager->GetClientHeartbeatIntervalMs());
925 int expected_disconnect_counter = 0; 991 EXPECT_EQ(1, test_connection_listener.get_disconnect_counter());
926 EXPECT_EQ(expected_disconnect_counter, 992
927 test_connection_listener.get_disconnect_counter()); 993 // Check that setting was persisted and will take effect upon restart.
928 994 BuildMCSClient();
929 interval_ms = 5 * 60 * 1000; // 5 minutes. A valid setting. 995 InitializeClient();
930 AddExpectedLoginRequest(std::vector<std::string>(), interval_ms); 996 LoginClientWithHeartbeat(std::vector<std::string>(), interval_ms);
931 mcs_client()->AddHeartbeatInterval(component_1, interval_ms); 997 PumpLoop();
932 // Setting was OK. HearbeatManager should get that setting now. 998
933 EXPECT_TRUE(hb_manager.HasClientHeartbeatInterval()); 999 // HB manger uses the shortest persisted interval after restart.
934 EXPECT_EQ(interval_ms, hb_manager.GetClientHeartbeatIntervalMs()); 1000 hb_manager = mcs_client()->GetHeartbeatManagerForTesting();
935 1001 EXPECT_TRUE(hb_manager->HasClientHeartbeatInterval());
936 ++expected_disconnect_counter; 1002 EXPECT_EQ(interval_ms, hb_manager->GetClientHeartbeatIntervalMs());
937 EXPECT_EQ(expected_disconnect_counter, 1003
938 test_connection_listener.get_disconnect_counter()); 1004 mcs_client()->RemoveHeartbeatInterval(component_1);
1005 PumpLoop();
1006
1007 // Check that setting was persisted and will take effect upon restart.
1008 BuildMCSClient();
1009 InitializeClient();
1010 LoginClientWithHeartbeat(std::vector<std::string>(), 0);
1011 PumpLoop();
1012
1013 hb_manager = mcs_client()->GetHeartbeatManagerForTesting();
1014 EXPECT_FALSE(hb_manager->HasClientHeartbeatInterval());
1015 }
1016
1017 // Tests adding custom heartbeat interval before connection is initialized.
1018 TEST_F(MCSClientTest, CustomHeartbeatIntervalSetBeforeInitialize) {
1019 BuildMCSClient();
1020
1021 const std::string component_1 = "component1";
1022 int interval_ms = 5 * 60 * 1000; // 5 minutes. A valid setting.
1023 mcs_client()->AddHeartbeatInterval(component_1, interval_ms);
1024 InitializeClient();
1025 LoginClientWithHeartbeat(std::vector<std::string>(), interval_ms);
1026 HeartbeatManager* hb_manager = mcs_client()->GetHeartbeatManagerForTesting();
1027 EXPECT_TRUE(hb_manager->HasClientHeartbeatInterval());
1028 }
1029
1030 // Tests adding custom heartbeat interval after connection is initialized, but
1031 // but before login is sent.
1032 TEST_F(MCSClientTest, CustomHeartbeatIntervalSetBeforeLogin) {
1033 BuildMCSClient();
1034
1035 const std::string component_1 = "component1";
1036 int interval_ms = 5 * 60 * 1000; // 5 minutes. A valid setting.
1037 InitializeClient();
1038 mcs_client()->AddHeartbeatInterval(component_1, interval_ms);
1039 LoginClientWithHeartbeat(std::vector<std::string>(), interval_ms);
1040 HeartbeatManager* hb_manager = mcs_client()->GetHeartbeatManagerForTesting();
1041 EXPECT_TRUE(hb_manager->HasClientHeartbeatInterval());
1042 }
1043
1044 // Tests situation when two heartbeat intervals are set and second is longer.
1045 // Covers both connection restart and storing of custom intervals.
1046 TEST_F(MCSClientTest, CustomHeartbeatIntervalSecondIntervalLonger) {
1047 BuildMCSClient();
1048 InitializeClient();
1049 LoginClient(std::vector<std::string>());
1050 PumpLoop();
1051 StoreCredentials();
1052
1053 TestConnectionListener test_connection_listener;
1054 connection_factory()->SetConnectionListener(&test_connection_listener);
1055
1056 HeartbeatManager* hb_manager = mcs_client()->GetHeartbeatManagerForTesting();
1057
1058 const std::string component_1 = "component1";
1059 int interval_ms = 5 * 60 * 1000; // 5 minutes. A valid setting.
1060
1061 AddExpectedLoginRequest(std::vector<std::string>(), interval_ms);
1062 mcs_client()->AddHeartbeatInterval(component_1, interval_ms);
1063 PumpLoop();
939 1064
940 const std::string component_2 = "component2"; 1065 const std::string component_2 = "component2";
941 int other_interval_ms = 10 * 60 * 1000; // 10 minutes. A valid setting. 1066 int other_interval_ms = 10 * 60 * 1000; // 10 minutes. A valid setting.
942 mcs_client()->AddHeartbeatInterval(component_2, other_interval_ms); 1067 mcs_client()->AddHeartbeatInterval(component_2, other_interval_ms);
943 // Setting was OK, but higher than the previous setting and HearbeatManager 1068 PumpLoop();
944 // will not be updated. 1069
945 EXPECT_TRUE(hb_manager.HasClientHeartbeatInterval()); 1070 // Interval was OK, but longer. HearbeatManager will use the first one.
946 EXPECT_EQ(interval_ms, hb_manager.GetClientHeartbeatIntervalMs()); 1071 EXPECT_TRUE(hb_manager->HasClientHeartbeatInterval());
947 // No connection reset expected. 1072 EXPECT_EQ(interval_ms, hb_manager->GetClientHeartbeatIntervalMs());
948 EXPECT_EQ(expected_disconnect_counter, 1073 EXPECT_EQ(1, test_connection_listener.get_disconnect_counter());
949 test_connection_listener.get_disconnect_counter()); 1074
950 1075 // Check that setting was persisted and will take effect upon restart.
951 other_interval_ms = 3 * 60 * 1000; // 3 minutes. A valid setting. 1076 BuildMCSClient();
1077 InitializeClient();
1078 LoginClientWithHeartbeat(std::vector<std::string>(), interval_ms);
1079 PumpLoop();
1080
1081 // HB manger uses the shortest persisted interval after restart.
1082 hb_manager = mcs_client()->GetHeartbeatManagerForTesting();
1083 EXPECT_TRUE(hb_manager->HasClientHeartbeatInterval());
1084 EXPECT_EQ(interval_ms, hb_manager->GetClientHeartbeatIntervalMs());
1085 }
1086
1087 // Tests situation when two heartbeat intervals are set and second is shorter.
1088 // Covers both connection restart and storing of custom intervals.
1089 TEST_F(MCSClientTest, CustomHeartbeatIntervalSecondIntervalShorter) {
1090 BuildMCSClient();
1091 InitializeClient();
1092 LoginClient(std::vector<std::string>());
1093 PumpLoop();
1094 StoreCredentials();
1095
1096 TestConnectionListener test_connection_listener;
1097 connection_factory()->SetConnectionListener(&test_connection_listener);
1098
1099 HeartbeatManager* hb_manager = mcs_client()->GetHeartbeatManagerForTesting();
1100
1101 const std::string component_1 = "component1";
1102 int interval_ms = 5 * 60 * 1000; // 5 minutes. A valid setting.
1103
1104 AddExpectedLoginRequest(std::vector<std::string>(), interval_ms);
1105 mcs_client()->AddHeartbeatInterval(component_1, interval_ms);
1106 PumpLoop();
1107
1108 const std::string component_2 = "component2";
1109 int other_interval_ms = 3 * 60 * 1000; // 3 minutes. A valid setting.
952 AddExpectedLoginRequest(std::vector<std::string>(), other_interval_ms); 1110 AddExpectedLoginRequest(std::vector<std::string>(), other_interval_ms);
953 mcs_client()->AddHeartbeatInterval(component_2, other_interval_ms); 1111 mcs_client()->AddHeartbeatInterval(component_2, other_interval_ms);
954 // Setting was OK and lower then present setting. HearbeatManager should get 1112 PumpLoop();
955 // that setting now. 1113 // Interval was OK. HearbeatManager should get that setting now.
956 EXPECT_TRUE(hb_manager.HasClientHeartbeatInterval()); 1114 EXPECT_TRUE(hb_manager->HasClientHeartbeatInterval());
957 EXPECT_EQ(other_interval_ms, hb_manager.GetClientHeartbeatIntervalMs()); 1115 EXPECT_EQ(other_interval_ms, hb_manager->GetClientHeartbeatIntervalMs());
958 ++expected_disconnect_counter; 1116 EXPECT_EQ(2, test_connection_listener.get_disconnect_counter());
959 EXPECT_EQ(expected_disconnect_counter, 1117
960 test_connection_listener.get_disconnect_counter()); 1118 // Check that setting was persisted and will take effect upon restart.
1119 BuildMCSClient();
1120 InitializeClient();
1121 LoginClientWithHeartbeat(std::vector<std::string>(), other_interval_ms);
1122 PumpLoop();
1123
1124 // HB manger uses the shortest persisted interval after restart.
1125 hb_manager = mcs_client()->GetHeartbeatManagerForTesting();
1126 EXPECT_TRUE(hb_manager->HasClientHeartbeatInterval());
1127 EXPECT_EQ(other_interval_ms, hb_manager->GetClientHeartbeatIntervalMs());
1128 }
1129
1130 // Tests situation shorter of two intervals is removed.
1131 // Covers both connection restart and storing of custom intervals.
1132 TEST_F(MCSClientTest, CustomHeartbeatIntervalRemoveShorterInterval) {
1133 BuildMCSClient();
1134 InitializeClient();
1135 LoginClient(std::vector<std::string>());
1136 PumpLoop();
1137 StoreCredentials();
1138
1139 TestConnectionListener test_connection_listener;
1140 connection_factory()->SetConnectionListener(&test_connection_listener);
1141
1142 HeartbeatManager* hb_manager = mcs_client()->GetHeartbeatManagerForTesting();
1143
1144 const std::string component_1 = "component1";
1145 int interval_ms = 5 * 60 * 1000; // 5 minutes. A valid setting.
1146
1147 AddExpectedLoginRequest(std::vector<std::string>(), interval_ms);
1148 mcs_client()->AddHeartbeatInterval(component_1, interval_ms);
1149 PumpLoop();
1150
1151 const std::string component_2 = "component2";
1152 int other_interval_ms = 3 * 60 * 1000; // 3 minutes. A valid setting.
1153 AddExpectedLoginRequest(std::vector<std::string>(), other_interval_ms);
1154 mcs_client()->AddHeartbeatInterval(component_2, other_interval_ms);
1155 PumpLoop();
961 1156
962 mcs_client()->RemoveHeartbeatInterval(component_2); 1157 mcs_client()->RemoveHeartbeatInterval(component_2);
1158 PumpLoop();
1159
963 // Removing the lowest setting reverts to second lowest. 1160 // Removing the lowest setting reverts to second lowest.
964 EXPECT_TRUE(hb_manager.HasClientHeartbeatInterval()); 1161 EXPECT_TRUE(hb_manager->HasClientHeartbeatInterval());
965 EXPECT_EQ(interval_ms, hb_manager.GetClientHeartbeatIntervalMs()); 1162 EXPECT_EQ(interval_ms, hb_manager->GetClientHeartbeatIntervalMs());
966 // No connection reset expected. 1163 // No connection reset expected.
967 EXPECT_EQ(expected_disconnect_counter, 1164 EXPECT_EQ(2, test_connection_listener.get_disconnect_counter());
968 test_connection_listener.get_disconnect_counter()); 1165
969 1166 // Check that setting was persisted and will take effect upon restart.
970 mcs_client()->RemoveHeartbeatInterval(component_1); 1167 BuildMCSClient();
971 // Removing all of the intervals, removes it from the HeartbeatManager. 1168 InitializeClient();
972 EXPECT_FALSE(hb_manager.HasClientHeartbeatInterval()); 1169 LoginClientWithHeartbeat(std::vector<std::string>(), interval_ms);
973 // No connection reset expected. 1170 PumpLoop();
974 EXPECT_EQ(expected_disconnect_counter, 1171
975 test_connection_listener.get_disconnect_counter()); 1172 // HB manger uses the shortest persisted interval after restart.
976 1173 hb_manager = mcs_client()->GetHeartbeatManagerForTesting();
977 mcs_client()->AddHeartbeatInterval(component_2, other_interval_ms); 1174 EXPECT_TRUE(hb_manager->HasClientHeartbeatInterval());
978 mcs_client()->AddHeartbeatInterval(component_1, interval_ms); 1175 EXPECT_EQ(interval_ms, hb_manager->GetClientHeartbeatIntervalMs());
979 EXPECT_TRUE(hb_manager.HasClientHeartbeatInterval());
980 EXPECT_EQ(other_interval_ms, hb_manager.GetClientHeartbeatIntervalMs());
981 // No connection reset expected.
982 EXPECT_EQ(expected_disconnect_counter,
983 test_connection_listener.get_disconnect_counter());
984
985 // Removing interval other than lowest does not change anything.
986 mcs_client()->RemoveHeartbeatInterval(component_1);
987 EXPECT_TRUE(hb_manager.HasClientHeartbeatInterval());
988 EXPECT_EQ(other_interval_ms, hb_manager.GetClientHeartbeatIntervalMs());
989 // No connection reset expected.
990 EXPECT_EQ(expected_disconnect_counter,
991 test_connection_listener.get_disconnect_counter());
992 } 1176 }
993 1177
994 } // namespace 1178 } // namespace
995 1179
996 } // namespace gcm 1180 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/engine/mcs_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698