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

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

Issue 1785613006: Make GCMDriver::GetInstanceIDHandler protected, to avoid misuse (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify by removing provider Created 4 years, 9 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
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 <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
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 void GCMDriverInstanceIDTest::RemoveInstanceIDData(const std::string& app_id) {
Peter Beverloo 2016/03/10 21:11:23 newline!!``oneone
johnme 2016/03/11 15:56:04 Done.
1261 driver()->GetInstanceIDHandlerInternal()->RemoveInstanceIDData(app_id);
1262 }
1263
1255 TEST_F(GCMDriverInstanceIDTest, InstanceIDData) { 1264 TEST_F(GCMDriverInstanceIDTest, InstanceIDData) {
1256 GetReady(); 1265 GetReady();
1257 1266
1258 driver()->AddInstanceIDData(kTestAppID1, kInstanceID1, "Foo"); 1267 AddInstanceIDData(kTestAppID1, kInstanceID1, "Foo");
1259 GetInstanceID(kTestAppID1, GCMDriverTest::WAIT); 1268 GetInstanceID(kTestAppID1, GCMDriverTest::WAIT);
1260 1269
1261 EXPECT_EQ(kInstanceID1, instance_id()); 1270 EXPECT_EQ(kInstanceID1, instance_id());
1262 EXPECT_EQ("Foo", extra_data()); 1271 EXPECT_EQ("Foo", extra_data());
1263 1272
1264 driver()->RemoveInstanceIDData(kTestAppID1); 1273 RemoveInstanceIDData(kTestAppID1);
1265 GetInstanceID(kTestAppID1, GCMDriverTest::WAIT); 1274 GetInstanceID(kTestAppID1, GCMDriverTest::WAIT);
1266 1275
1267 EXPECT_TRUE(instance_id().empty()); 1276 EXPECT_TRUE(instance_id().empty());
1268 EXPECT_TRUE(extra_data().empty()); 1277 EXPECT_TRUE(extra_data().empty());
1269 } 1278 }
1270 1279
1271 TEST_F(GCMDriverInstanceIDTest, GCMClientNotReadyBeforeInstanceIDData) { 1280 TEST_F(GCMDriverInstanceIDTest, GCMClientNotReadyBeforeInstanceIDData) {
1272 CreateDriver(); 1281 CreateDriver();
1273 PumpIOLoop(); 1282 PumpIOLoop();
1274 PumpUILoop(); 1283 PumpUILoop();
1275 1284
1276 // Make GCMClient not ready until PerformDelayedStart is called. 1285 // Make GCMClient not ready until PerformDelayedStart is called.
1277 GetGCMClient()->set_start_mode_overridding( 1286 GetGCMClient()->set_start_mode_overridding(
1278 FakeGCMClient::FORCE_TO_ALWAYS_DELAY_START_GCM); 1287 FakeGCMClient::FORCE_TO_ALWAYS_DELAY_START_GCM);
1279 1288
1280 AddAppHandlers(); 1289 AddAppHandlers();
1281 1290
1282 // All operations are on hold until GCMClient is ready. 1291 // All operations are on hold until GCMClient is ready.
1283 driver()->AddInstanceIDData(kTestAppID1, kInstanceID1, "Foo"); 1292 AddInstanceIDData(kTestAppID1, kInstanceID1, "Foo");
1284 driver()->AddInstanceIDData(kTestAppID2, kInstanceID2, "Bar"); 1293 AddInstanceIDData(kTestAppID2, kInstanceID2, "Bar");
1285 driver()->RemoveInstanceIDData(kTestAppID1); 1294 RemoveInstanceIDData(kTestAppID1);
1286 GetInstanceID(kTestAppID2, GCMDriverTest::DO_NOT_WAIT); 1295 GetInstanceID(kTestAppID2, GCMDriverTest::DO_NOT_WAIT);
1287 PumpIOLoop(); 1296 PumpIOLoop();
1288 PumpUILoop(); 1297 PumpUILoop();
1289 EXPECT_TRUE(instance_id().empty()); 1298 EXPECT_TRUE(instance_id().empty());
1290 EXPECT_TRUE(extra_data().empty()); 1299 EXPECT_TRUE(extra_data().empty());
1291 1300
1292 // All operations will be performed after GCMClient becomes ready. 1301 // All operations will be performed after GCMClient becomes ready.
1293 GetGCMClient()->PerformDelayedStart(); 1302 GetGCMClient()->PerformDelayedStart();
1294 WaitForAsyncOperation(); 1303 WaitForAsyncOperation();
1295 EXPECT_EQ(kInstanceID2, instance_id()); 1304 EXPECT_EQ(kInstanceID2, instance_id());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 PumpUILoop(); 1381 PumpUILoop();
1373 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, unregistration_result()); 1382 EXPECT_EQ(GCMClient::UNKNOWN_ERROR, unregistration_result());
1374 1383
1375 // DeleteToken operation will be invoked after GCMClient becomes ready. 1384 // DeleteToken operation will be invoked after GCMClient becomes ready.
1376 GetGCMClient()->PerformDelayedStart(); 1385 GetGCMClient()->PerformDelayedStart();
1377 WaitForAsyncOperation(); 1386 WaitForAsyncOperation();
1378 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result()); 1387 EXPECT_EQ(GCMClient::SUCCESS, unregistration_result());
1379 } 1388 }
1380 1389
1381 } // namespace gcm 1390 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698