OLD | NEW |
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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1170 void GetInstanceIDDataCompleted(const std::string& instance_id, | 1170 void GetInstanceIDDataCompleted(const std::string& instance_id, |
1171 const std::string& extra_data); | 1171 const std::string& extra_data); |
1172 void GetToken(const std::string& app_id, | 1172 void GetToken(const std::string& app_id, |
1173 const std::string& authorized_entity, | 1173 const std::string& authorized_entity, |
1174 const std::string& scope, | 1174 const std::string& scope, |
1175 WaitToFinish wait_to_finish); | 1175 WaitToFinish wait_to_finish); |
1176 void DeleteToken(const std::string& app_id, | 1176 void DeleteToken(const std::string& app_id, |
1177 const std::string& authorized_entity, | 1177 const std::string& authorized_entity, |
1178 const std::string& scope, | 1178 const std::string& scope, |
1179 WaitToFinish wait_to_finish); | 1179 WaitToFinish wait_to_finish); |
| 1180 void AddInstanceIDData(const std::string& app_id, |
| 1181 const std::string& instance_id, |
| 1182 const std::string& extra_data); |
| 1183 void RemoveInstanceIDData(const std::string& app_id); |
1180 | 1184 |
1181 std::string instance_id() const { return instance_id_; } | 1185 std::string instance_id() const { return instance_id_; } |
1182 std::string extra_data() const { return extra_data_; } | 1186 std::string extra_data() const { return extra_data_; } |
1183 | 1187 |
1184 private: | 1188 private: |
1185 std::string instance_id_; | 1189 std::string instance_id_; |
1186 std::string extra_data_; | 1190 std::string extra_data_; |
1187 | 1191 |
1188 DISALLOW_COPY_AND_ASSIGN(GCMDriverInstanceIDTest); | 1192 DISALLOW_COPY_AND_ASSIGN(GCMDriverInstanceIDTest); |
1189 }; | 1193 }; |
1190 | 1194 |
1191 GCMDriverInstanceIDTest::GCMDriverInstanceIDTest() { | 1195 GCMDriverInstanceIDTest::GCMDriverInstanceIDTest() { |
1192 } | 1196 } |
1193 | 1197 |
1194 GCMDriverInstanceIDTest::~GCMDriverInstanceIDTest() { | 1198 GCMDriverInstanceIDTest::~GCMDriverInstanceIDTest() { |
1195 } | 1199 } |
1196 | 1200 |
1197 void GCMDriverInstanceIDTest::GetReady() { | 1201 void GCMDriverInstanceIDTest::GetReady() { |
1198 CreateDriver(); | 1202 CreateDriver(); |
1199 AddAppHandlers(); | 1203 AddAppHandlers(); |
1200 PumpIOLoop(); | 1204 PumpIOLoop(); |
1201 PumpUILoop(); | 1205 PumpUILoop(); |
1202 } | 1206 } |
1203 | 1207 |
1204 void GCMDriverInstanceIDTest::GetInstanceID(const std::string& app_id, | 1208 void GCMDriverInstanceIDTest::GetInstanceID(const std::string& app_id, |
1205 WaitToFinish wait_to_finish) { | 1209 WaitToFinish wait_to_finish) { |
1206 base::RunLoop run_loop; | 1210 base::RunLoop run_loop; |
1207 set_async_operation_completed_callback(run_loop.QuitClosure()); | 1211 set_async_operation_completed_callback(run_loop.QuitClosure()); |
1208 driver()->GetInstanceIDData(app_id, | 1212 driver()->GetInstanceIDHandlerInternal()->GetInstanceIDData( |
1209 base::Bind(&GCMDriverInstanceIDTest::GetInstanceIDDataCompleted, | 1213 app_id, base::Bind(&GCMDriverInstanceIDTest::GetInstanceIDDataCompleted, |
1210 base::Unretained(this))); | 1214 base::Unretained(this))); |
1211 if (wait_to_finish == WAIT) | 1215 if (wait_to_finish == WAIT) |
1212 run_loop.Run(); | 1216 run_loop.Run(); |
1213 } | 1217 } |
1214 | 1218 |
1215 void GCMDriverInstanceIDTest::GetInstanceIDDataCompleted( | 1219 void GCMDriverInstanceIDTest::GetInstanceIDDataCompleted( |
1216 const std::string& instance_id, const std::string& extra_data) { | 1220 const std::string& instance_id, const std::string& extra_data) { |
1217 instance_id_ = instance_id; | 1221 instance_id_ = instance_id; |
1218 extra_data_ = extra_data; | 1222 extra_data_ = extra_data; |
1219 if (!async_operation_completed_callback().is_null()) | 1223 if (!async_operation_completed_callback().is_null()) |
1220 async_operation_completed_callback().Run(); | 1224 async_operation_completed_callback().Run(); |
1221 } | 1225 } |
1222 | 1226 |
1223 void GCMDriverInstanceIDTest::GetToken(const std::string& app_id, | 1227 void GCMDriverInstanceIDTest::GetToken(const std::string& app_id, |
1224 const std::string& authorized_entity, | 1228 const std::string& authorized_entity, |
1225 const std::string& scope, | 1229 const std::string& scope, |
1226 WaitToFinish wait_to_finish) { | 1230 WaitToFinish wait_to_finish) { |
1227 base::RunLoop run_loop; | 1231 base::RunLoop run_loop; |
1228 set_async_operation_completed_callback(run_loop.QuitClosure()); | 1232 set_async_operation_completed_callback(run_loop.QuitClosure()); |
1229 std::map<std::string, std::string> options; | 1233 std::map<std::string, std::string> options; |
1230 driver()->GetToken(app_id, | 1234 driver()->GetInstanceIDHandlerInternal()->GetToken( |
1231 authorized_entity, | 1235 app_id, authorized_entity, scope, options, |
1232 scope, | 1236 base::Bind(&GCMDriverTest::RegisterCompleted, base::Unretained(this))); |
1233 options, | |
1234 base::Bind(&GCMDriverTest::RegisterCompleted, | |
1235 base::Unretained(this))); | |
1236 if (wait_to_finish == WAIT) | 1237 if (wait_to_finish == WAIT) |
1237 run_loop.Run(); | 1238 run_loop.Run(); |
1238 } | 1239 } |
1239 | 1240 |
1240 void GCMDriverInstanceIDTest::DeleteToken(const std::string& app_id, | 1241 void GCMDriverInstanceIDTest::DeleteToken(const std::string& app_id, |
1241 const std::string& authorized_entity, | 1242 const std::string& authorized_entity, |
1242 const std::string& scope, | 1243 const std::string& scope, |
1243 WaitToFinish wait_to_finish) { | 1244 WaitToFinish wait_to_finish) { |
1244 base::RunLoop run_loop; | 1245 base::RunLoop run_loop; |
1245 set_async_operation_completed_callback(run_loop.QuitClosure()); | 1246 set_async_operation_completed_callback(run_loop.QuitClosure()); |
1246 driver()->DeleteToken(app_id, | 1247 driver()->GetInstanceIDHandlerInternal()->DeleteToken( |
1247 authorized_entity, | 1248 app_id, authorized_entity, scope, |
1248 scope, | 1249 base::Bind(&GCMDriverTest::UnregisterCompleted, base::Unretained(this))); |
1249 base::Bind(&GCMDriverTest::UnregisterCompleted, | |
1250 base::Unretained(this))); | |
1251 if (wait_to_finish == WAIT) | 1250 if (wait_to_finish == WAIT) |
1252 run_loop.Run(); | 1251 run_loop.Run(); |
1253 } | 1252 } |
1254 | 1253 |
| 1254 void GCMDriverInstanceIDTest::AddInstanceIDData(const std::string& app_id, |
| 1255 const std::string& instance_id, |
| 1256 const std::string& extra_data) { |
| 1257 driver()->GetInstanceIDHandlerInternal()->AddInstanceIDData( |
| 1258 app_id, instance_id, extra_data); |
| 1259 } |
| 1260 |
| 1261 void GCMDriverInstanceIDTest::RemoveInstanceIDData(const std::string& app_id) { |
| 1262 driver()->GetInstanceIDHandlerInternal()->RemoveInstanceIDData(app_id); |
| 1263 } |
| 1264 |
1255 TEST_F(GCMDriverInstanceIDTest, InstanceIDData) { | 1265 TEST_F(GCMDriverInstanceIDTest, InstanceIDData) { |
1256 GetReady(); | 1266 GetReady(); |
1257 | 1267 |
1258 driver()->AddInstanceIDData(kTestAppID1, kInstanceID1, "Foo"); | 1268 AddInstanceIDData(kTestAppID1, kInstanceID1, "Foo"); |
1259 GetInstanceID(kTestAppID1, GCMDriverTest::WAIT); | 1269 GetInstanceID(kTestAppID1, GCMDriverTest::WAIT); |
1260 | 1270 |
1261 EXPECT_EQ(kInstanceID1, instance_id()); | 1271 EXPECT_EQ(kInstanceID1, instance_id()); |
1262 EXPECT_EQ("Foo", extra_data()); | 1272 EXPECT_EQ("Foo", extra_data()); |
1263 | 1273 |
1264 driver()->RemoveInstanceIDData(kTestAppID1); | 1274 RemoveInstanceIDData(kTestAppID1); |
1265 GetInstanceID(kTestAppID1, GCMDriverTest::WAIT); | 1275 GetInstanceID(kTestAppID1, GCMDriverTest::WAIT); |
1266 | 1276 |
1267 EXPECT_TRUE(instance_id().empty()); | 1277 EXPECT_TRUE(instance_id().empty()); |
1268 EXPECT_TRUE(extra_data().empty()); | 1278 EXPECT_TRUE(extra_data().empty()); |
1269 } | 1279 } |
1270 | 1280 |
1271 TEST_F(GCMDriverInstanceIDTest, GCMClientNotReadyBeforeInstanceIDData) { | 1281 TEST_F(GCMDriverInstanceIDTest, GCMClientNotReadyBeforeInstanceIDData) { |
1272 CreateDriver(); | 1282 CreateDriver(); |
1273 PumpIOLoop(); | 1283 PumpIOLoop(); |
1274 PumpUILoop(); | 1284 PumpUILoop(); |
1275 | 1285 |
1276 // Make GCMClient not ready until PerformDelayedStart is called. | 1286 // Make GCMClient not ready until PerformDelayedStart is called. |
1277 GetGCMClient()->set_start_mode_overridding( | 1287 GetGCMClient()->set_start_mode_overridding( |
1278 FakeGCMClient::FORCE_TO_ALWAYS_DELAY_START_GCM); | 1288 FakeGCMClient::FORCE_TO_ALWAYS_DELAY_START_GCM); |
1279 | 1289 |
1280 AddAppHandlers(); | 1290 AddAppHandlers(); |
1281 | 1291 |
1282 // All operations are on hold until GCMClient is ready. | 1292 // All operations are on hold until GCMClient is ready. |
1283 driver()->AddInstanceIDData(kTestAppID1, kInstanceID1, "Foo"); | 1293 AddInstanceIDData(kTestAppID1, kInstanceID1, "Foo"); |
1284 driver()->AddInstanceIDData(kTestAppID2, kInstanceID2, "Bar"); | 1294 AddInstanceIDData(kTestAppID2, kInstanceID2, "Bar"); |
1285 driver()->RemoveInstanceIDData(kTestAppID1); | 1295 RemoveInstanceIDData(kTestAppID1); |
1286 GetInstanceID(kTestAppID2, GCMDriverTest::DO_NOT_WAIT); | 1296 GetInstanceID(kTestAppID2, GCMDriverTest::DO_NOT_WAIT); |
1287 PumpIOLoop(); | 1297 PumpIOLoop(); |
1288 PumpUILoop(); | 1298 PumpUILoop(); |
1289 EXPECT_TRUE(instance_id().empty()); | 1299 EXPECT_TRUE(instance_id().empty()); |
1290 EXPECT_TRUE(extra_data().empty()); | 1300 EXPECT_TRUE(extra_data().empty()); |
1291 | 1301 |
1292 // All operations will be performed after GCMClient becomes ready. | 1302 // All operations will be performed after GCMClient becomes ready. |
1293 GetGCMClient()->PerformDelayedStart(); | 1303 GetGCMClient()->PerformDelayedStart(); |
1294 WaitForAsyncOperation(); | 1304 WaitForAsyncOperation(); |
1295 EXPECT_EQ(kInstanceID2, instance_id()); | 1305 EXPECT_EQ(kInstanceID2, instance_id()); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1372 PumpUILoop(); | 1382 PumpUILoop(); |
1373 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, unregistration_result()); | 1383 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, unregistration_result()); |
1374 | 1384 |
1375 // DeleteToken operation will be invoked after GCMClient becomes ready. | 1385 // DeleteToken operation will be invoked after GCMClient becomes ready. |
1376 GetGCMClient()->PerformDelayedStart(); | 1386 GetGCMClient()->PerformDelayedStart(); |
1377 WaitForAsyncOperation(); | 1387 WaitForAsyncOperation(); |
1378 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result()); | 1388 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result()); |
1379 } | 1389 } |
1380 | 1390 |
1381 } // namespace gcm | 1391 } // namespace gcm |
OLD | NEW |