| OLD | NEW |
| 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 "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/power_monitor/power_monitor.h" | 10 #include "base/power_monitor/power_monitor.h" |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 367 |
| 368 bool Register(const BackgroundSyncRegistrationOptions& sync_options) { | 368 bool Register(const BackgroundSyncRegistrationOptions& sync_options) { |
| 369 return RegisterWithServiceWorkerId(sw_registration_id_1_, sync_options); | 369 return RegisterWithServiceWorkerId(sw_registration_id_1_, sync_options); |
| 370 } | 370 } |
| 371 | 371 |
| 372 bool RegisterWithServiceWorkerId( | 372 bool RegisterWithServiceWorkerId( |
| 373 int64 sw_registration_id, | 373 int64 sw_registration_id, |
| 374 const BackgroundSyncRegistrationOptions& options) { | 374 const BackgroundSyncRegistrationOptions& options) { |
| 375 bool was_called = false; | 375 bool was_called = false; |
| 376 background_sync_manager_->Register( | 376 background_sync_manager_->Register( |
| 377 sw_registration_id, options, true /* requested_from_service_worker */, | 377 sw_registration_id, options, |
| 378 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, | 378 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, |
| 379 base::Unretained(this), &was_called)); | 379 base::Unretained(this), &was_called)); |
| 380 base::RunLoop().RunUntilIdle(); | 380 base::RunLoop().RunUntilIdle(); |
| 381 EXPECT_TRUE(was_called); | |
| 382 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; | |
| 383 } | |
| 384 | |
| 385 bool RegisterFromDocumentWithServiceWorkerId( | |
| 386 int64 sw_registration_id, | |
| 387 const BackgroundSyncRegistrationOptions& options) { | |
| 388 bool was_called = false; | |
| 389 background_sync_manager_->Register( | |
| 390 sw_registration_id, options, false /* requested_from_service_worker */, | |
| 391 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, | |
| 392 base::Unretained(this), &was_called)); | |
| 393 base::RunLoop().RunUntilIdle(); | |
| 394 EXPECT_TRUE(was_called); | 381 EXPECT_TRUE(was_called); |
| 395 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; | 382 return callback_status_ == BACKGROUND_SYNC_STATUS_OK; |
| 396 } | 383 } |
| 397 | 384 |
| 398 bool Unregister(const BackgroundSyncRegistration& sync_registration) { | 385 bool Unregister(const BackgroundSyncRegistration& sync_registration) { |
| 399 return UnregisterWithServiceWorkerId(sw_registration_id_1_, | 386 return UnregisterWithServiceWorkerId(sw_registration_id_1_, |
| 400 sync_registration); | 387 sync_registration); |
| 401 } | 388 } |
| 402 | 389 |
| 403 bool UnregisterWithServiceWorkerId( | 390 bool UnregisterWithServiceWorkerId( |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 // the operations complete sequentially. | 775 // the operations complete sequentially. |
| 789 SetupDelayedBackgroundSyncManager(); | 776 SetupDelayedBackgroundSyncManager(); |
| 790 | 777 |
| 791 const int64 kExpectedInitialId = BackgroundSyncRegistration::kInitialId; | 778 const int64 kExpectedInitialId = BackgroundSyncRegistration::kInitialId; |
| 792 | 779 |
| 793 bool register_called = false; | 780 bool register_called = false; |
| 794 bool unregister_called = false; | 781 bool unregister_called = false; |
| 795 bool get_registration_called = false; | 782 bool get_registration_called = false; |
| 796 test_background_sync_manager_->Register( | 783 test_background_sync_manager_->Register( |
| 797 sw_registration_id_1_, sync_options_1_, | 784 sw_registration_id_1_, sync_options_1_, |
| 798 true /* requested_from_service_worker */, | |
| 799 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, | 785 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, |
| 800 base::Unretained(this), ®ister_called)); | 786 base::Unretained(this), ®ister_called)); |
| 801 test_background_sync_manager_->Unregister( | 787 test_background_sync_manager_->Unregister( |
| 802 sw_registration_id_1_, sync_options_1_.tag, sync_options_1_.periodicity, | 788 sw_registration_id_1_, sync_options_1_.tag, sync_options_1_.periodicity, |
| 803 kExpectedInitialId, | 789 kExpectedInitialId, |
| 804 base::Bind(&BackgroundSyncManagerTest::StatusCallback, | 790 base::Bind(&BackgroundSyncManagerTest::StatusCallback, |
| 805 base::Unretained(this), &unregister_called)); | 791 base::Unretained(this), &unregister_called)); |
| 806 test_background_sync_manager_->GetRegistration( | 792 test_background_sync_manager_->GetRegistration( |
| 807 sw_registration_id_1_, sync_options_1_.tag, sync_options_1_.periodicity, | 793 sw_registration_id_1_, sync_options_1_.tag, sync_options_1_.periodicity, |
| 808 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, | 794 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 } | 832 } |
| 847 | 833 |
| 848 TEST_F(BackgroundSyncManagerTest, | 834 TEST_F(BackgroundSyncManagerTest, |
| 849 UnregisterServiceWorkerDuringSyncRegistration) { | 835 UnregisterServiceWorkerDuringSyncRegistration) { |
| 850 EXPECT_TRUE(Register(sync_options_1_)); | 836 EXPECT_TRUE(Register(sync_options_1_)); |
| 851 | 837 |
| 852 test_background_sync_manager_->set_delay_backend(true); | 838 test_background_sync_manager_->set_delay_backend(true); |
| 853 bool callback_called = false; | 839 bool callback_called = false; |
| 854 test_background_sync_manager_->Register( | 840 test_background_sync_manager_->Register( |
| 855 sw_registration_id_1_, sync_options_2_, | 841 sw_registration_id_1_, sync_options_2_, |
| 856 true /* requested_from_service_worker */, | |
| 857 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, | 842 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, |
| 858 base::Unretained(this), &callback_called)); | 843 base::Unretained(this), &callback_called)); |
| 859 | 844 |
| 860 base::RunLoop().RunUntilIdle(); | 845 base::RunLoop().RunUntilIdle(); |
| 861 EXPECT_FALSE(callback_called); | 846 EXPECT_FALSE(callback_called); |
| 862 UnregisterServiceWorker(sw_registration_id_1_); | 847 UnregisterServiceWorker(sw_registration_id_1_); |
| 863 | 848 |
| 864 test_background_sync_manager_->Continue(); | 849 test_background_sync_manager_->Continue(); |
| 865 base::RunLoop().RunUntilIdle(); | 850 base::RunLoop().RunUntilIdle(); |
| 866 EXPECT_TRUE(callback_called); | 851 EXPECT_TRUE(callback_called); |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1277 RemoveWindowClients(); | 1262 RemoveWindowClients(); |
| 1278 EXPECT_FALSE(Register(sync_options_1_)); | 1263 EXPECT_FALSE(Register(sync_options_1_)); |
| 1279 } | 1264 } |
| 1280 | 1265 |
| 1281 TEST_F(BackgroundSyncManagerTest, RegisterExistingFailsWithoutWindow) { | 1266 TEST_F(BackgroundSyncManagerTest, RegisterExistingFailsWithoutWindow) { |
| 1282 EXPECT_TRUE(Register(sync_options_1_)); | 1267 EXPECT_TRUE(Register(sync_options_1_)); |
| 1283 RemoveWindowClients(); | 1268 RemoveWindowClients(); |
| 1284 EXPECT_FALSE(Register(sync_options_1_)); | 1269 EXPECT_FALSE(Register(sync_options_1_)); |
| 1285 } | 1270 } |
| 1286 | 1271 |
| 1287 TEST_F(BackgroundSyncManagerTest, RegisterSucceedsFromUncontrolledWindow) { | |
| 1288 RemoveWindowClients(); | |
| 1289 EXPECT_TRUE(RegisterFromDocumentWithServiceWorkerId(sw_registration_id_1_, | |
| 1290 sync_options_1_)); | |
| 1291 } | |
| 1292 | |
| 1293 TEST_F(BackgroundSyncManagerTest, UnregisterSucceedsWithoutWindow) { | 1272 TEST_F(BackgroundSyncManagerTest, UnregisterSucceedsWithoutWindow) { |
| 1294 EXPECT_TRUE(Register(sync_options_1_)); | 1273 EXPECT_TRUE(Register(sync_options_1_)); |
| 1295 RemoveWindowClients(); | 1274 RemoveWindowClients(); |
| 1296 EXPECT_TRUE(Unregister(callback_registration_)); | 1275 EXPECT_TRUE(Unregister(callback_registration_)); |
| 1297 EXPECT_FALSE(GetRegistration(sync_options_1_)); | 1276 EXPECT_FALSE(GetRegistration(sync_options_1_)); |
| 1298 } | 1277 } |
| 1299 | 1278 |
| 1300 } // namespace content | 1279 } // namespace content |
| OLD | NEW |