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

Side by Side Diff: content/browser/background_sync/background_sync_manager_unittest.cc

Issue 1527183003: Change mojo enums to be scoped enums in the generated C++ bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-binding-equals
Patch Set: rebase Created 4 years, 11 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/browser/background_sync/background_sync_manager.h" 5 #include "content/browser/background_sync/background_sync_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 void HasMainFrameProviderHost(const GURL& origin, 282 void HasMainFrameProviderHost(const GURL& origin,
283 const BoolCallback& callback) override { 283 const BoolCallback& callback) override {
284 callback.Run(has_main_frame_provider_host_); 284 callback.Run(has_main_frame_provider_host_);
285 } 285 }
286 286
287 private: 287 private:
288 bool corrupt_backend_ = false; 288 bool corrupt_backend_ = false;
289 bool delay_backend_ = false; 289 bool delay_backend_ = false;
290 bool has_main_frame_provider_host_ = true; 290 bool has_main_frame_provider_host_ = true;
291 BackgroundSyncEventLastChance last_chance_ = 291 BackgroundSyncEventLastChance last_chance_ =
292 BACKGROUND_SYNC_EVENT_LAST_CHANCE_IS_NOT_LAST_CHANCE; 292 BackgroundSyncEventLastChance::IS_NOT_LAST_CHANCE;
293 base::Closure continuation_; 293 base::Closure continuation_;
294 OneShotCallback one_shot_callback_; 294 OneShotCallback one_shot_callback_;
295 base::Closure delayed_task_; 295 base::Closure delayed_task_;
296 base::TimeDelta delayed_task_delta_; 296 base::TimeDelta delayed_task_delta_;
297 }; 297 };
298 298
299 class BackgroundSyncManagerTest : public testing::Test { 299 class BackgroundSyncManagerTest : public testing::Test {
300 public: 300 public:
301 BackgroundSyncManagerTest() 301 BackgroundSyncManagerTest()
302 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), 302 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 base::Unretained(this), &was_called)); 526 base::Unretained(this), &was_called));
527 base::RunLoop().RunUntilIdle(); 527 base::RunLoop().RunUntilIdle();
528 EXPECT_TRUE(was_called); 528 EXPECT_TRUE(was_called);
529 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; 529 return callback_status_ == BACKGROUND_SYNC_STATUS_OK;
530 } 530 }
531 531
532 bool NotifyWhenFinished( 532 bool NotifyWhenFinished(
533 BackgroundSyncRegistrationHandle* registration_handle) { 533 BackgroundSyncRegistrationHandle* registration_handle) {
534 callback_finished_called_ = false; 534 callback_finished_called_ = false;
535 callback_finished_status_ = BACKGROUND_SYNC_STATUS_NOT_FOUND; 535 callback_finished_status_ = BACKGROUND_SYNC_STATUS_NOT_FOUND;
536 callback_finished_state_ = BACKGROUND_SYNC_STATE_FAILED; 536 callback_finished_state_ = BackgroundSyncState::FAILED;
537 537
538 registration_handle->NotifyWhenFinished( 538 registration_handle->NotifyWhenFinished(
539 base::Bind(&NotifyWhenFinishedCallback, &callback_finished_called_, 539 base::Bind(&NotifyWhenFinishedCallback, &callback_finished_called_,
540 &callback_finished_status_, &callback_finished_state_)); 540 &callback_finished_status_, &callback_finished_state_));
541 base::RunLoop().RunUntilIdle(); 541 base::RunLoop().RunUntilIdle();
542 542
543 if (callback_finished_called_) 543 if (callback_finished_called_)
544 EXPECT_EQ(BACKGROUND_SYNC_STATUS_OK, callback_finished_status_); 544 EXPECT_EQ(BACKGROUND_SYNC_STATUS_OK, callback_finished_status_);
545 545
546 return callback_finished_called_; 546 return callback_finished_called_;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 684
685 // Callback values. 685 // Callback values.
686 BackgroundSyncStatus callback_status_ = BACKGROUND_SYNC_STATUS_OK; 686 BackgroundSyncStatus callback_status_ = BACKGROUND_SYNC_STATUS_OK;
687 scoped_ptr<BackgroundSyncRegistrationHandle> callback_registration_handle_; 687 scoped_ptr<BackgroundSyncRegistrationHandle> callback_registration_handle_;
688 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>> 688 scoped_ptr<ScopedVector<BackgroundSyncRegistrationHandle>>
689 callback_registration_handles_; 689 callback_registration_handles_;
690 ServiceWorkerStatusCode callback_sw_status_code_ = SERVICE_WORKER_OK; 690 ServiceWorkerStatusCode callback_sw_status_code_ = SERVICE_WORKER_OK;
691 bool callback_finished_called_ = false; 691 bool callback_finished_called_ = false;
692 BackgroundSyncStatus callback_finished_status_ = 692 BackgroundSyncStatus callback_finished_status_ =
693 BACKGROUND_SYNC_STATUS_NOT_FOUND; 693 BACKGROUND_SYNC_STATUS_NOT_FOUND;
694 BackgroundSyncState callback_finished_state_ = BACKGROUND_SYNC_STATE_FAILED; 694 BackgroundSyncState callback_finished_state_ = BackgroundSyncState::FAILED;
695 int sync_events_called_ = 0; 695 int sync_events_called_ = 0;
696 ServiceWorkerVersion::StatusCallback sync_fired_callback_; 696 ServiceWorkerVersion::StatusCallback sync_fired_callback_;
697 }; 697 };
698 698
699 TEST_F(BackgroundSyncManagerTest, Register) { 699 TEST_F(BackgroundSyncManagerTest, Register) {
700 EXPECT_TRUE(Register(sync_options_1_)); 700 EXPECT_TRUE(Register(sync_options_1_));
701 } 701 }
702 702
703 TEST_F(BackgroundSyncManagerTest, RegistractionIntact) { 703 TEST_F(BackgroundSyncManagerTest, RegistractionIntact) {
704 EXPECT_TRUE(Register(sync_options_1_)); 704 EXPECT_TRUE(Register(sync_options_1_));
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1183 EXPECT_FALSE(GetRegistration(sync_options_1_));
1184 } 1184 }
1185 1185
1186 TEST_F(BackgroundSyncManagerTest, NotifyWhenFinishedAfterEventSuccess) { 1186 TEST_F(BackgroundSyncManagerTest, NotifyWhenFinishedAfterEventSuccess) {
1187 InitSyncEventTest(); 1187 InitSyncEventTest();
1188 1188
1189 EXPECT_TRUE(Register(sync_options_1_)); 1189 EXPECT_TRUE(Register(sync_options_1_));
1190 EXPECT_EQ(1, sync_events_called_); 1190 EXPECT_EQ(1, sync_events_called_);
1191 1191
1192 EXPECT_TRUE(NotifyWhenFinished(callback_registration_handle_.get())); 1192 EXPECT_TRUE(NotifyWhenFinished(callback_registration_handle_.get()));
1193 EXPECT_EQ(BACKGROUND_SYNC_STATE_SUCCESS, FinishedState()); 1193 EXPECT_EQ(BackgroundSyncState::SUCCESS, FinishedState());
1194 } 1194 }
1195 1195
1196 TEST_F(BackgroundSyncManagerTest, NotifyWhenFinishedBeforeEventSuccess) { 1196 TEST_F(BackgroundSyncManagerTest, NotifyWhenFinishedBeforeEventSuccess) {
1197 InitDelayedSyncEventTest(); 1197 InitDelayedSyncEventTest();
1198 1198
1199 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1199 RegisterAndVerifySyncEventDelayed(sync_options_1_);
1200 1200
1201 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get())); 1201 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get()));
1202 1202
1203 // Finish firing the event. 1203 // Finish firing the event.
1204 sync_fired_callback_.Run(SERVICE_WORKER_OK); 1204 sync_fired_callback_.Run(SERVICE_WORKER_OK);
1205 base::RunLoop().RunUntilIdle(); 1205 base::RunLoop().RunUntilIdle();
1206 EXPECT_EQ(1, sync_events_called_); 1206 EXPECT_EQ(1, sync_events_called_);
1207 EXPECT_EQ(BACKGROUND_SYNC_STATE_SUCCESS, FinishedState()); 1207 EXPECT_EQ(BackgroundSyncState::SUCCESS, FinishedState());
1208 } 1208 }
1209 1209
1210 TEST_F(BackgroundSyncManagerTest, 1210 TEST_F(BackgroundSyncManagerTest,
1211 NotifyWhenFinishedBeforeUnregisteredEventSuccess) { 1211 NotifyWhenFinishedBeforeUnregisteredEventSuccess) {
1212 InitDelayedSyncEventTest(); 1212 InitDelayedSyncEventTest();
1213 1213
1214 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1214 RegisterAndVerifySyncEventDelayed(sync_options_1_);
1215 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get())); 1215 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get()));
1216 1216
1217 // Unregistering should set the state to UNREGISTERED but finished shouldn't 1217 // Unregistering should set the state to UNREGISTERED but finished shouldn't
1218 // be called until the event finishes firing, at which point its state should 1218 // be called until the event finishes firing, at which point its state should
1219 // be SUCCESS. 1219 // be SUCCESS.
1220 EXPECT_TRUE(Unregister(callback_registration_handle_.get())); 1220 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
1221 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1221 EXPECT_FALSE(GetRegistration(sync_options_1_));
1222 1222
1223 // Finish firing the event. 1223 // Finish firing the event.
1224 sync_fired_callback_.Run(SERVICE_WORKER_OK); 1224 sync_fired_callback_.Run(SERVICE_WORKER_OK);
1225 base::RunLoop().RunUntilIdle(); 1225 base::RunLoop().RunUntilIdle();
1226 EXPECT_EQ(BACKGROUND_SYNC_STATE_SUCCESS, FinishedState()); 1226 EXPECT_EQ(BackgroundSyncState::SUCCESS, FinishedState());
1227 } 1227 }
1228 1228
1229 TEST_F(BackgroundSyncManagerTest, 1229 TEST_F(BackgroundSyncManagerTest,
1230 NotifyWhenFinishedBeforeUnregisteredEventFailure) { 1230 NotifyWhenFinishedBeforeUnregisteredEventFailure) {
1231 InitDelayedSyncEventTest(); 1231 InitDelayedSyncEventTest();
1232 1232
1233 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1233 RegisterAndVerifySyncEventDelayed(sync_options_1_);
1234 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get())); 1234 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get()));
1235 1235
1236 // Unregistering should set the state to UNREGISTERED but finished shouldn't 1236 // Unregistering should set the state to UNREGISTERED but finished shouldn't
1237 // be called until the event finishes firing, at which point its state should 1237 // be called until the event finishes firing, at which point its state should
1238 // be FAILED. 1238 // be FAILED.
1239 EXPECT_TRUE(Unregister(callback_registration_handle_.get())); 1239 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
1240 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1240 EXPECT_FALSE(GetRegistration(sync_options_1_));
1241 1241
1242 // Finish firing the event. 1242 // Finish firing the event.
1243 sync_fired_callback_.Run(SERVICE_WORKER_ERROR_FAILED); 1243 sync_fired_callback_.Run(SERVICE_WORKER_ERROR_FAILED);
1244 base::RunLoop().RunUntilIdle(); 1244 base::RunLoop().RunUntilIdle();
1245 EXPECT_EQ(1, sync_events_called_); 1245 EXPECT_EQ(1, sync_events_called_);
1246 EXPECT_EQ(BACKGROUND_SYNC_STATE_FAILED, FinishedState()); 1246 EXPECT_EQ(BackgroundSyncState::FAILED, FinishedState());
1247 } 1247 }
1248 1248
1249 TEST_F(BackgroundSyncManagerTest, 1249 TEST_F(BackgroundSyncManagerTest,
1250 NotifyWhenFinishedBeforeUnregisteredEventFires) { 1250 NotifyWhenFinishedBeforeUnregisteredEventFires) {
1251 InitSyncEventTest(); 1251 InitSyncEventTest();
1252 1252
1253 SetNetwork(net::NetworkChangeNotifier::CONNECTION_NONE); 1253 SetNetwork(net::NetworkChangeNotifier::CONNECTION_NONE);
1254 EXPECT_TRUE(Register(sync_options_1_)); 1254 EXPECT_TRUE(Register(sync_options_1_));
1255 EXPECT_TRUE(Unregister(callback_registration_handle_.get())); 1255 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
1256 EXPECT_TRUE(NotifyWhenFinished(callback_registration_handle_.get())); 1256 EXPECT_TRUE(NotifyWhenFinished(callback_registration_handle_.get()));
1257 EXPECT_EQ(BACKGROUND_SYNC_STATE_UNREGISTERED, FinishedState()); 1257 EXPECT_EQ(BackgroundSyncState::UNREGISTERED, FinishedState());
1258 } 1258 }
1259 1259
1260 TEST_F(BackgroundSyncManagerTest, 1260 TEST_F(BackgroundSyncManagerTest,
1261 NotifyWhenFinishedBeforeEventSuccessDroppedHandle) { 1261 NotifyWhenFinishedBeforeEventSuccessDroppedHandle) {
1262 InitDelayedSyncEventTest(); 1262 InitDelayedSyncEventTest();
1263 1263
1264 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1264 RegisterAndVerifySyncEventDelayed(sync_options_1_);
1265 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get())); 1265 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get()));
1266 1266
1267 // Drop the client's handle to the registration before the event fires, ensure 1267 // Drop the client's handle to the registration before the event fires, ensure
1268 // that the finished callback is still run. 1268 // that the finished callback is still run.
1269 callback_registration_handle_ = nullptr; 1269 callback_registration_handle_ = nullptr;
1270 1270
1271 // Finish firing the event. 1271 // Finish firing the event.
1272 sync_fired_callback_.Run(SERVICE_WORKER_OK); 1272 sync_fired_callback_.Run(SERVICE_WORKER_OK);
1273 base::RunLoop().RunUntilIdle(); 1273 base::RunLoop().RunUntilIdle();
1274 EXPECT_EQ(1, sync_events_called_); 1274 EXPECT_EQ(1, sync_events_called_);
1275 EXPECT_EQ(BACKGROUND_SYNC_STATE_SUCCESS, FinishedState()); 1275 EXPECT_EQ(BackgroundSyncState::SUCCESS, FinishedState());
1276 } 1276 }
1277 1277
1278 TEST_F(BackgroundSyncManagerTest, NotifyWhenFinishedAfterEventFailure) { 1278 TEST_F(BackgroundSyncManagerTest, NotifyWhenFinishedAfterEventFailure) {
1279 InitFailedSyncEventTest(); 1279 InitFailedSyncEventTest();
1280 1280
1281 EXPECT_TRUE(Register(sync_options_1_)); 1281 EXPECT_TRUE(Register(sync_options_1_));
1282 EXPECT_EQ(1, sync_events_called_); 1282 EXPECT_EQ(1, sync_events_called_);
1283 1283
1284 EXPECT_TRUE(NotifyWhenFinished(callback_registration_handle_.get())); 1284 EXPECT_TRUE(NotifyWhenFinished(callback_registration_handle_.get()));
1285 EXPECT_EQ(BACKGROUND_SYNC_STATE_FAILED, FinishedState()); 1285 EXPECT_EQ(BackgroundSyncState::FAILED, FinishedState());
1286 } 1286 }
1287 1287
1288 TEST_F(BackgroundSyncManagerTest, NotifyWhenFinishedBeforeEventFailure) { 1288 TEST_F(BackgroundSyncManagerTest, NotifyWhenFinishedBeforeEventFailure) {
1289 InitDelayedSyncEventTest(); 1289 InitDelayedSyncEventTest();
1290 1290
1291 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1291 RegisterAndVerifySyncEventDelayed(sync_options_1_);
1292 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get())); 1292 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get()));
1293 1293
1294 // Finish firing the event. 1294 // Finish firing the event.
1295 sync_fired_callback_.Run(SERVICE_WORKER_ERROR_FAILED); 1295 sync_fired_callback_.Run(SERVICE_WORKER_ERROR_FAILED);
1296 base::RunLoop().RunUntilIdle(); 1296 base::RunLoop().RunUntilIdle();
1297 EXPECT_EQ(BACKGROUND_SYNC_STATE_FAILED, FinishedState()); 1297 EXPECT_EQ(BackgroundSyncState::FAILED, FinishedState());
1298 } 1298 }
1299 1299
1300 TEST_F(BackgroundSyncManagerTest, NotifyWhenFinishedAfterUnregistered) { 1300 TEST_F(BackgroundSyncManagerTest, NotifyWhenFinishedAfterUnregistered) {
1301 EXPECT_TRUE(Register(sync_options_1_)); 1301 EXPECT_TRUE(Register(sync_options_1_));
1302 EXPECT_TRUE(Unregister(callback_registration_handle_.get())); 1302 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
1303 1303
1304 EXPECT_TRUE(NotifyWhenFinished(callback_registration_handle_.get())); 1304 EXPECT_TRUE(NotifyWhenFinished(callback_registration_handle_.get()));
1305 EXPECT_EQ(BACKGROUND_SYNC_STATE_UNREGISTERED, FinishedState()); 1305 EXPECT_EQ(BackgroundSyncState::UNREGISTERED, FinishedState());
1306 } 1306 }
1307 1307
1308 TEST_F(BackgroundSyncManagerTest, NotifyWhenFinishedBeforeUnregistered) { 1308 TEST_F(BackgroundSyncManagerTest, NotifyWhenFinishedBeforeUnregistered) {
1309 Register(sync_options_1_); 1309 Register(sync_options_1_);
1310 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get())); 1310 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get()));
1311 EXPECT_TRUE(Unregister(callback_registration_handle_.get())); 1311 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
1312 EXPECT_EQ(BACKGROUND_SYNC_STATE_UNREGISTERED, FinishedState()); 1312 EXPECT_EQ(BackgroundSyncState::UNREGISTERED, FinishedState());
1313 } 1313 }
1314 1314
1315 TEST_F(BackgroundSyncManagerTest, ReregisterMidSyncFirstAttemptFails) { 1315 TEST_F(BackgroundSyncManagerTest, ReregisterMidSyncFirstAttemptFails) {
1316 InitDelayedSyncEventTest(); 1316 InitDelayedSyncEventTest();
1317 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1317 RegisterAndVerifySyncEventDelayed(sync_options_1_);
1318 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get())); 1318 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get()));
1319 1319
1320 // Reregister the event mid-sync 1320 // Reregister the event mid-sync
1321 EXPECT_TRUE(Register(sync_options_1_)); 1321 EXPECT_TRUE(Register(sync_options_1_));
1322 1322
1323 // The first sync attempt fails. 1323 // The first sync attempt fails.
1324 sync_fired_callback_.Run(SERVICE_WORKER_ERROR_FAILED); 1324 sync_fired_callback_.Run(SERVICE_WORKER_ERROR_FAILED);
1325 base::RunLoop().RunUntilIdle(); 1325 base::RunLoop().RunUntilIdle();
1326 EXPECT_FALSE(callback_finished_called_); 1326 EXPECT_FALSE(callback_finished_called_);
1327 1327
1328 // It should fire again since it was reregistered mid-sync. 1328 // It should fire again since it was reregistered mid-sync.
1329 EXPECT_TRUE(GetRegistration(sync_options_1_)); 1329 EXPECT_TRUE(GetRegistration(sync_options_1_));
1330 sync_fired_callback_.Run(SERVICE_WORKER_OK); 1330 sync_fired_callback_.Run(SERVICE_WORKER_OK);
1331 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1331 EXPECT_FALSE(GetRegistration(sync_options_1_));
1332 EXPECT_EQ(BACKGROUND_SYNC_STATE_SUCCESS, FinishedState()); 1332 EXPECT_EQ(BackgroundSyncState::SUCCESS, FinishedState());
1333 } 1333 }
1334 1334
1335 TEST_F(BackgroundSyncManagerTest, ReregisterMidSyncFirstAttemptSucceeds) { 1335 TEST_F(BackgroundSyncManagerTest, ReregisterMidSyncFirstAttemptSucceeds) {
1336 InitDelayedSyncEventTest(); 1336 InitDelayedSyncEventTest();
1337 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1337 RegisterAndVerifySyncEventDelayed(sync_options_1_);
1338 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get())); 1338 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get()));
1339 1339
1340 // Reregister the event mid-sync 1340 // Reregister the event mid-sync
1341 EXPECT_TRUE(Register(sync_options_1_)); 1341 EXPECT_TRUE(Register(sync_options_1_));
1342 1342
1343 // The first sync event succeeds. 1343 // The first sync event succeeds.
1344 sync_fired_callback_.Run(SERVICE_WORKER_OK); 1344 sync_fired_callback_.Run(SERVICE_WORKER_OK);
1345 base::RunLoop().RunUntilIdle(); 1345 base::RunLoop().RunUntilIdle();
1346 EXPECT_FALSE(callback_finished_called_); 1346 EXPECT_FALSE(callback_finished_called_);
1347 1347
1348 // It should fire again since it was reregistered mid-sync. 1348 // It should fire again since it was reregistered mid-sync.
1349 EXPECT_TRUE(GetRegistration(sync_options_1_)); 1349 EXPECT_TRUE(GetRegistration(sync_options_1_));
1350 sync_fired_callback_.Run(SERVICE_WORKER_OK); 1350 sync_fired_callback_.Run(SERVICE_WORKER_OK);
1351 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1351 EXPECT_FALSE(GetRegistration(sync_options_1_));
1352 EXPECT_EQ(BACKGROUND_SYNC_STATE_SUCCESS, FinishedState()); 1352 EXPECT_EQ(BackgroundSyncState::SUCCESS, FinishedState());
1353 } 1353 }
1354 1354
1355 TEST_F(BackgroundSyncManagerTest, 1355 TEST_F(BackgroundSyncManagerTest,
1356 NotifyUnregisteredMidSyncNoRetryAttemptsLeft) { 1356 NotifyUnregisteredMidSyncNoRetryAttemptsLeft) {
1357 InitDelayedSyncEventTest(); 1357 InitDelayedSyncEventTest();
1358 1358
1359 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1359 RegisterAndVerifySyncEventDelayed(sync_options_1_);
1360 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get())); 1360 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get()));
1361 1361
1362 // Unregister the event mid-sync. 1362 // Unregister the event mid-sync.
1363 EXPECT_TRUE(Unregister(callback_registration_handle_.get())); 1363 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
1364 1364
1365 // Finish firing the event. 1365 // Finish firing the event.
1366 sync_fired_callback_.Run(SERVICE_WORKER_ERROR_FAILED); 1366 sync_fired_callback_.Run(SERVICE_WORKER_ERROR_FAILED);
1367 base::RunLoop().RunUntilIdle(); 1367 base::RunLoop().RunUntilIdle();
1368 1368
1369 // Since there were no retry attempts left, the sync ultimately failed. 1369 // Since there were no retry attempts left, the sync ultimately failed.
1370 EXPECT_EQ(BACKGROUND_SYNC_STATE_FAILED, FinishedState()); 1370 EXPECT_EQ(BackgroundSyncState::FAILED, FinishedState());
1371 } 1371 }
1372 1372
1373 TEST_F(BackgroundSyncManagerTest, 1373 TEST_F(BackgroundSyncManagerTest,
1374 NotifyUnregisteredMidSyncWithRetryAttemptsLeft) { 1374 NotifyUnregisteredMidSyncWithRetryAttemptsLeft) {
1375 SetMaxSyncAttemptsAndRestartManager(2); 1375 SetMaxSyncAttemptsAndRestartManager(2);
1376 InitDelayedSyncEventTest(); 1376 InitDelayedSyncEventTest();
1377 1377
1378 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1378 RegisterAndVerifySyncEventDelayed(sync_options_1_);
1379 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get())); 1379 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get()));
1380 1380
1381 // Unregister the event mid-sync. 1381 // Unregister the event mid-sync.
1382 EXPECT_TRUE(Unregister(callback_registration_handle_.get())); 1382 EXPECT_TRUE(Unregister(callback_registration_handle_.get()));
1383 1383
1384 // Finish firing the event. 1384 // Finish firing the event.
1385 sync_fired_callback_.Run(SERVICE_WORKER_ERROR_FAILED); 1385 sync_fired_callback_.Run(SERVICE_WORKER_ERROR_FAILED);
1386 base::RunLoop().RunUntilIdle(); 1386 base::RunLoop().RunUntilIdle();
1387 // Since there was one retry attempt left, the sync didn't completely fail 1387 // Since there was one retry attempt left, the sync didn't completely fail
1388 // before it was unregistered. 1388 // before it was unregistered.
1389 EXPECT_EQ(BACKGROUND_SYNC_STATE_UNREGISTERED, FinishedState()); 1389 EXPECT_EQ(BackgroundSyncState::UNREGISTERED, FinishedState());
1390 } 1390 }
1391 1391
1392 TEST_F(BackgroundSyncManagerTest, OverwritePendingRegistration) { 1392 TEST_F(BackgroundSyncManagerTest, OverwritePendingRegistration) {
1393 // An overwritten pending registration should complete with 1393 // An overwritten pending registration should complete with
1394 // BACKGROUND_SYNC_STATE_UNREGISTERED. 1394 // BackgroundSyncState::UNREGISTERED.
1395 sync_options_1_.power_state = POWER_STATE_AVOID_DRAINING; 1395 sync_options_1_.power_state = POWER_STATE_AVOID_DRAINING;
1396 EXPECT_TRUE(Register(sync_options_1_)); 1396 EXPECT_TRUE(Register(sync_options_1_));
1397 EXPECT_TRUE(GetRegistration(sync_options_1_)); 1397 EXPECT_TRUE(GetRegistration(sync_options_1_));
1398 EXPECT_EQ(POWER_STATE_AVOID_DRAINING, 1398 EXPECT_EQ(POWER_STATE_AVOID_DRAINING,
1399 callback_registration_handle_->options()->power_state); 1399 callback_registration_handle_->options()->power_state);
1400 scoped_ptr<BackgroundSyncRegistrationHandle> original_handle = 1400 scoped_ptr<BackgroundSyncRegistrationHandle> original_handle =
1401 std::move(callback_registration_handle_); 1401 std::move(callback_registration_handle_);
1402 1402
1403 // Overwrite the pending registration. 1403 // Overwrite the pending registration.
1404 sync_options_1_.power_state = POWER_STATE_AUTO; 1404 sync_options_1_.power_state = POWER_STATE_AUTO;
1405 EXPECT_TRUE(Register(sync_options_1_)); 1405 EXPECT_TRUE(Register(sync_options_1_));
1406 EXPECT_TRUE(GetRegistration(sync_options_1_)); 1406 EXPECT_TRUE(GetRegistration(sync_options_1_));
1407 EXPECT_EQ(POWER_STATE_AUTO, 1407 EXPECT_EQ(POWER_STATE_AUTO,
1408 callback_registration_handle_->options()->power_state); 1408 callback_registration_handle_->options()->power_state);
1409 1409
1410 EXPECT_TRUE(NotifyWhenFinished(original_handle.get())); 1410 EXPECT_TRUE(NotifyWhenFinished(original_handle.get()));
1411 EXPECT_EQ(BACKGROUND_SYNC_STATE_UNREGISTERED, FinishedState()); 1411 EXPECT_EQ(BackgroundSyncState::UNREGISTERED, FinishedState());
1412 EXPECT_EQ(0, sync_events_called_); 1412 EXPECT_EQ(0, sync_events_called_);
1413 } 1413 }
1414 1414
1415 TEST_F(BackgroundSyncManagerTest, OverwriteFiringRegistrationWhichSucceeds) { 1415 TEST_F(BackgroundSyncManagerTest, OverwriteFiringRegistrationWhichSucceeds) {
1416 // An overwritten pending registration should complete with 1416 // An overwritten pending registration should complete with
1417 // BACKGROUND_SYNC_STATE_SUCCESS if firing completes successfully. 1417 // BackgroundSyncState::SUCCESS if firing completes successfully.
1418 InitDelayedSyncEventTest(); 1418 InitDelayedSyncEventTest();
1419 1419
1420 sync_options_1_.power_state = POWER_STATE_AVOID_DRAINING; 1420 sync_options_1_.power_state = POWER_STATE_AVOID_DRAINING;
1421 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1421 RegisterAndVerifySyncEventDelayed(sync_options_1_);
1422 scoped_ptr<BackgroundSyncRegistrationHandle> original_handle = 1422 scoped_ptr<BackgroundSyncRegistrationHandle> original_handle =
1423 std::move(callback_registration_handle_); 1423 std::move(callback_registration_handle_);
1424 1424
1425 // The next registration won't block. 1425 // The next registration won't block.
1426 InitSyncEventTest(); 1426 InitSyncEventTest();
1427 1427
1428 // Overwrite the firing registration. 1428 // Overwrite the firing registration.
1429 sync_options_1_.power_state = POWER_STATE_AUTO; 1429 sync_options_1_.power_state = POWER_STATE_AUTO;
1430 EXPECT_TRUE(Register(sync_options_1_)); 1430 EXPECT_TRUE(Register(sync_options_1_));
1431 EXPECT_FALSE(NotifyWhenFinished(original_handle.get())); 1431 EXPECT_FALSE(NotifyWhenFinished(original_handle.get()));
1432 1432
1433 // Successfully finish the first event. 1433 // Successfully finish the first event.
1434 sync_fired_callback_.Run(SERVICE_WORKER_OK); 1434 sync_fired_callback_.Run(SERVICE_WORKER_OK);
1435 base::RunLoop().RunUntilIdle(); 1435 base::RunLoop().RunUntilIdle();
1436 EXPECT_EQ(BACKGROUND_SYNC_STATE_SUCCESS, FinishedState()); 1436 EXPECT_EQ(BackgroundSyncState::SUCCESS, FinishedState());
1437 } 1437 }
1438 1438
1439 TEST_F(BackgroundSyncManagerTest, OverwriteFiringRegistrationWhichFails) { 1439 TEST_F(BackgroundSyncManagerTest, OverwriteFiringRegistrationWhichFails) {
1440 // An overwritten pending registration should complete with 1440 // An overwritten pending registration should complete with
1441 // BACKGROUND_SYNC_STATE_FAILED if firing fails. 1441 // BackgroundSyncState::FAILED if firing fails.
1442 InitDelayedSyncEventTest(); 1442 InitDelayedSyncEventTest();
1443 1443
1444 sync_options_1_.power_state = POWER_STATE_AVOID_DRAINING; 1444 sync_options_1_.power_state = POWER_STATE_AVOID_DRAINING;
1445 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1445 RegisterAndVerifySyncEventDelayed(sync_options_1_);
1446 scoped_ptr<BackgroundSyncRegistrationHandle> original_handle = 1446 scoped_ptr<BackgroundSyncRegistrationHandle> original_handle =
1447 std::move(callback_registration_handle_); 1447 std::move(callback_registration_handle_);
1448 1448
1449 // The next registration won't block. 1449 // The next registration won't block.
1450 InitSyncEventTest(); 1450 InitSyncEventTest();
1451 1451
1452 // Overwrite the firing registration. 1452 // Overwrite the firing registration.
1453 sync_options_1_.power_state = POWER_STATE_AUTO; 1453 sync_options_1_.power_state = POWER_STATE_AUTO;
1454 EXPECT_TRUE(Register(sync_options_1_)); 1454 EXPECT_TRUE(Register(sync_options_1_));
1455 EXPECT_FALSE(NotifyWhenFinished(original_handle.get())); 1455 EXPECT_FALSE(NotifyWhenFinished(original_handle.get()));
1456 1456
1457 // Fail the first event. 1457 // Fail the first event.
1458 sync_fired_callback_.Run(SERVICE_WORKER_ERROR_FAILED); 1458 sync_fired_callback_.Run(SERVICE_WORKER_ERROR_FAILED);
1459 base::RunLoop().RunUntilIdle(); 1459 base::RunLoop().RunUntilIdle();
1460 EXPECT_EQ(BACKGROUND_SYNC_STATE_FAILED, FinishedState()); 1460 EXPECT_EQ(BackgroundSyncState::FAILED, FinishedState());
1461 } 1461 }
1462 1462
1463 TEST_F(BackgroundSyncManagerTest, DisableWhilePendingNotifiesFinished) { 1463 TEST_F(BackgroundSyncManagerTest, DisableWhilePendingNotifiesFinished) {
1464 InitSyncEventTest(); 1464 InitSyncEventTest();
1465 1465
1466 // Register a one-shot that must wait for network connectivity before it 1466 // Register a one-shot that must wait for network connectivity before it
1467 // can fire. 1467 // can fire.
1468 SetNetwork(net::NetworkChangeNotifier::CONNECTION_NONE); 1468 SetNetwork(net::NetworkChangeNotifier::CONNECTION_NONE);
1469 EXPECT_TRUE(Register(sync_options_1_)); 1469 EXPECT_TRUE(Register(sync_options_1_));
1470 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get())); 1470 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get()));
1471 1471
1472 // Corrupting the backend should result in the manager disabling itself on the 1472 // Corrupting the backend should result in the manager disabling itself on the
1473 // next operation. While disabling, it should finalize any pending 1473 // next operation. While disabling, it should finalize any pending
1474 // registrations. 1474 // registrations.
1475 test_background_sync_manager_->set_corrupt_backend(true); 1475 test_background_sync_manager_->set_corrupt_backend(true);
1476 EXPECT_FALSE(Register(sync_options_2_)); 1476 EXPECT_FALSE(Register(sync_options_2_));
1477 EXPECT_EQ(BACKGROUND_SYNC_STATE_UNREGISTERED, FinishedState()); 1477 EXPECT_EQ(BackgroundSyncState::UNREGISTERED, FinishedState());
1478 } 1478 }
1479 1479
1480 TEST_F(BackgroundSyncManagerTest, DisableWhileFiringNotifiesFinished) { 1480 TEST_F(BackgroundSyncManagerTest, DisableWhileFiringNotifiesFinished) {
1481 InitDelayedSyncEventTest(); 1481 InitDelayedSyncEventTest();
1482 1482
1483 // Register a one-shot that pauses mid-fire. 1483 // Register a one-shot that pauses mid-fire.
1484 RegisterAndVerifySyncEventDelayed(sync_options_1_); 1484 RegisterAndVerifySyncEventDelayed(sync_options_1_);
1485 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get())); 1485 EXPECT_FALSE(NotifyWhenFinished(callback_registration_handle_.get()));
1486 1486
1487 // Corrupting the backend should result in the manager disabling itself on the 1487 // Corrupting the backend should result in the manager disabling itself on the
1488 // next operation. Even though the manager is disabled, the firing sync event 1488 // next operation. Even though the manager is disabled, the firing sync event
1489 // should still be able to complete successfully and notify as much. 1489 // should still be able to complete successfully and notify as much.
1490 test_background_sync_manager_->set_corrupt_backend(true); 1490 test_background_sync_manager_->set_corrupt_backend(true);
1491 EXPECT_FALSE(Register(sync_options_2_)); 1491 EXPECT_FALSE(Register(sync_options_2_));
1492 EXPECT_FALSE(callback_finished_called_); 1492 EXPECT_FALSE(callback_finished_called_);
1493 test_background_sync_manager_->set_corrupt_backend(false); 1493 test_background_sync_manager_->set_corrupt_backend(false);
1494 1494
1495 // Successfully complete the firing event. 1495 // Successfully complete the firing event.
1496 sync_fired_callback_.Run(SERVICE_WORKER_OK); 1496 sync_fired_callback_.Run(SERVICE_WORKER_OK);
1497 base::RunLoop().RunUntilIdle(); 1497 base::RunLoop().RunUntilIdle();
1498 EXPECT_EQ(BACKGROUND_SYNC_STATE_SUCCESS, FinishedState()); 1498 EXPECT_EQ(BackgroundSyncState::SUCCESS, FinishedState());
1499 } 1499 }
1500 1500
1501 // TODO(jkarlin): Change this to a periodic test as one-shots can't be power 1501 // TODO(jkarlin): Change this to a periodic test as one-shots can't be power
1502 // dependent according to spec. 1502 // dependent according to spec.
1503 TEST_F(BackgroundSyncManagerTest, OneShotFiresOnPowerChange) { 1503 TEST_F(BackgroundSyncManagerTest, OneShotFiresOnPowerChange) {
1504 InitSyncEventTest(); 1504 InitSyncEventTest();
1505 sync_options_1_.power_state = POWER_STATE_AVOID_DRAINING; 1505 sync_options_1_.power_state = POWER_STATE_AVOID_DRAINING;
1506 1506
1507 SetOnBatteryPower(true); 1507 SetOnBatteryPower(true);
1508 EXPECT_TRUE(Register(sync_options_1_)); 1508 EXPECT_TRUE(Register(sync_options_1_));
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
2015 2015
2016 EXPECT_FALSE(GetRegistration(sync_options_1_)); 2016 EXPECT_FALSE(GetRegistration(sync_options_1_));
2017 EXPECT_FALSE(GetRegistration(sync_options_2_)); 2017 EXPECT_FALSE(GetRegistration(sync_options_2_));
2018 } 2018 }
2019 2019
2020 TEST_F(BackgroundSyncManagerTest, LastChance) { 2020 TEST_F(BackgroundSyncManagerTest, LastChance) {
2021 SetMaxSyncAttemptsAndRestartManager(2); 2021 SetMaxSyncAttemptsAndRestartManager(2);
2022 InitFailedSyncEventTest(); 2022 InitFailedSyncEventTest();
2023 2023
2024 EXPECT_TRUE(Register(sync_options_1_)); 2024 EXPECT_TRUE(Register(sync_options_1_));
2025 EXPECT_EQ(BACKGROUND_SYNC_EVENT_LAST_CHANCE_IS_NOT_LAST_CHANCE, 2025 EXPECT_EQ(BackgroundSyncEventLastChance::IS_NOT_LAST_CHANCE,
2026 test_background_sync_manager_->last_chance()); 2026 test_background_sync_manager_->last_chance());
2027 EXPECT_TRUE(GetRegistration(sync_options_1_)); 2027 EXPECT_TRUE(GetRegistration(sync_options_1_));
2028 2028
2029 // Run it again. 2029 // Run it again.
2030 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta()); 2030 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta());
2031 test_background_sync_manager_->delayed_task().Run(); 2031 test_background_sync_manager_->delayed_task().Run();
2032 base::RunLoop().RunUntilIdle(); 2032 base::RunLoop().RunUntilIdle();
2033 EXPECT_FALSE(GetRegistration(sync_options_1_)); 2033 EXPECT_FALSE(GetRegistration(sync_options_1_));
2034 EXPECT_EQ(BACKGROUND_SYNC_EVENT_LAST_CHANCE_IS_LAST_CHANCE, 2034 EXPECT_EQ(BackgroundSyncEventLastChance::IS_LAST_CHANCE,
2035 test_background_sync_manager_->last_chance()); 2035 test_background_sync_manager_->last_chance());
2036 } 2036 }
2037 2037
2038 } // namespace content 2038 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698