Chromium Code Reviews| 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/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "content/browser/browser_thread_impl.h" | 11 #include "content/browser/browser_thread_impl.h" |
| 12 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 12 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| 13 #include "content/browser/service_worker/service_worker_context_core.h" | 13 #include "content/browser/service_worker/service_worker_context_core.h" |
| 14 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 14 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 15 #include "content/browser/service_worker/service_worker_storage.h" | 15 #include "content/browser/service_worker/service_worker_storage.h" |
| 16 #include "content/public/test/test_browser_thread_bundle.h" | 16 #include "content/public/test/test_browser_thread_bundle.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 const char kOrigin[] = "https://example.com"; | |
| 24 const char kPattern1[] = "https://example.com/a"; | 23 const char kPattern1[] = "https://example.com/a"; |
| 25 const char kPattern2[] = "https://example.com/b"; | 24 const char kPattern2[] = "https://example.com/b"; |
| 26 const char kScript1[] = "https://example.com/a/script.js"; | 25 const char kScript1[] = "https://example.com/a/script.js"; |
| 27 const char kScript2[] = "https://example.com/b/script.js"; | 26 const char kScript2[] = "https://example.com/b/script.js"; |
| 28 const int kRenderProcessId = 99; | 27 const int kRenderProcessId = 99; |
| 29 | 28 |
| 30 void RegisterServiceWorkerCallback(bool* called, | 29 void RegisterServiceWorkerCallback(bool* called, |
| 31 int64* store_registration_id, | 30 int64* store_registration_id, |
| 32 ServiceWorkerStatusCode status, | 31 ServiceWorkerStatusCode status, |
| 33 const std::string& status_message, | 32 const std::string& status_message, |
| 34 int64 registration_id) { | 33 int64 registration_id) { |
| 35 EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status); | 34 EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status); |
| 36 *called = true; | 35 *called = true; |
| 37 *store_registration_id = registration_id; | 36 *store_registration_id = registration_id; |
| 38 } | 37 } |
| 39 | 38 |
| 39 void FindServiceWorkerRegistrationCallback( | |
| 40 scoped_refptr<ServiceWorkerRegistration>* out_registration, | |
| 41 ServiceWorkerStatusCode status, | |
| 42 const scoped_refptr<ServiceWorkerRegistration>& registration) { | |
| 43 EXPECT_EQ(SERVICE_WORKER_OK, status) << ServiceWorkerStatusToString(status); | |
| 44 *out_registration = registration; | |
| 45 } | |
| 46 | |
| 40 void UnregisterServiceWorkerCallback(bool* called, | 47 void UnregisterServiceWorkerCallback(bool* called, |
| 41 ServiceWorkerStatusCode code) { | 48 ServiceWorkerStatusCode code) { |
| 42 EXPECT_EQ(SERVICE_WORKER_OK, code); | 49 EXPECT_EQ(SERVICE_WORKER_OK, code); |
| 43 *called = true; | 50 *called = true; |
| 44 } | 51 } |
| 45 | 52 |
| 46 } // namespace | 53 } // namespace |
| 47 | 54 |
| 48 // A BackgroundSyncManager that can simulate delaying and corrupting the | 55 // A BackgroundSyncManager that can simulate delaying and corrupting the |
| 49 // backend. This class assumes (and verifies) that only one operation runs at a | 56 // backend. This class assumes (and verifies) that only one operation runs at a |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 void SetUp() override { | 155 void SetUp() override { |
| 149 helper_.reset( | 156 helper_.reset( |
| 150 new EmbeddedWorkerTestHelper(base::FilePath(), kRenderProcessId)); | 157 new EmbeddedWorkerTestHelper(base::FilePath(), kRenderProcessId)); |
| 151 | 158 |
| 152 background_sync_manager_ = | 159 background_sync_manager_ = |
| 153 BackgroundSyncManager::Create(helper_->context_wrapper()); | 160 BackgroundSyncManager::Create(helper_->context_wrapper()); |
| 154 | 161 |
| 155 // Wait for storage to finish initializing before registering service | 162 // Wait for storage to finish initializing before registering service |
| 156 // workers. | 163 // workers. |
| 157 base::RunLoop().RunUntilIdle(); | 164 base::RunLoop().RunUntilIdle(); |
| 165 RegisterServiceWorkers(); | |
| 166 } | |
| 158 | 167 |
| 168 void RegisterServiceWorkers() { | |
| 159 bool called_1 = false; | 169 bool called_1 = false; |
| 160 bool called_2 = false; | 170 bool called_2 = false; |
| 161 helper_->context()->RegisterServiceWorker( | 171 helper_->context()->RegisterServiceWorker( |
| 162 GURL(kPattern1), GURL(kScript1), NULL, | 172 GURL(kPattern1), GURL(kScript1), NULL, |
| 163 base::Bind(&RegisterServiceWorkerCallback, &called_1, | 173 base::Bind(&RegisterServiceWorkerCallback, &called_1, |
| 164 &sw_registration_id_1_)); | 174 &sw_registration_id_1_)); |
| 165 | 175 |
| 166 helper_->context()->RegisterServiceWorker( | 176 helper_->context()->RegisterServiceWorker( |
| 167 GURL(kPattern2), GURL(kScript2), NULL, | 177 GURL(kPattern2), GURL(kScript2), NULL, |
| 168 base::Bind(&RegisterServiceWorkerCallback, &called_2, | 178 base::Bind(&RegisterServiceWorkerCallback, &called_2, |
| 169 &sw_registration_id_2_)); | 179 &sw_registration_id_2_)); |
| 170 base::RunLoop().RunUntilIdle(); | 180 base::RunLoop().RunUntilIdle(); |
| 171 EXPECT_TRUE(called_1); | 181 EXPECT_TRUE(called_1); |
| 172 EXPECT_TRUE(called_2); | 182 EXPECT_TRUE(called_2); |
| 183 | |
| 184 // Hang onto the registrations as they need to be "live" when | |
| 185 // calling BackgroundSyncMasnager::Register. | |
|
jsbell
2015/04/28 20:52:33
Typo: "Masnager"
| |
| 186 helper_->context_wrapper()->FindRegistrationForId( | |
| 187 sw_registration_id_1_, GURL(kPattern1).GetOrigin(), | |
| 188 base::Bind(FindServiceWorkerRegistrationCallback, &sw_registration_1_)); | |
| 189 | |
| 190 helper_->context_wrapper()->FindRegistrationForId( | |
| 191 sw_registration_id_2_, GURL(kPattern1).GetOrigin(), | |
| 192 base::Bind(FindServiceWorkerRegistrationCallback, &sw_registration_2_)); | |
| 193 base::RunLoop().RunUntilIdle(); | |
| 194 EXPECT_TRUE(sw_registration_1_); | |
| 195 EXPECT_TRUE(sw_registration_2_); | |
| 173 } | 196 } |
| 174 | 197 |
| 175 void StatusAndRegistrationCallback( | 198 void StatusAndRegistrationCallback( |
| 176 bool* was_called, | 199 bool* was_called, |
| 177 BackgroundSyncManager::ErrorType error, | 200 BackgroundSyncManager::ErrorType error, |
| 178 const BackgroundSyncManager::BackgroundSyncRegistration& registration) { | 201 const BackgroundSyncManager::BackgroundSyncRegistration& registration) { |
| 179 *was_called = true; | 202 *was_called = true; |
| 180 callback_error_ = error; | 203 callback_error_ = error; |
| 181 callback_registration_ = registration; | 204 callback_registration_ = registration; |
| 182 } | 205 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 201 return RegisterWithServiceWorkerId(sw_registration_id_1_, | 224 return RegisterWithServiceWorkerId(sw_registration_id_1_, |
| 202 sync_registration); | 225 sync_registration); |
| 203 } | 226 } |
| 204 | 227 |
| 205 bool RegisterWithServiceWorkerId( | 228 bool RegisterWithServiceWorkerId( |
| 206 int64 sw_registration_id, | 229 int64 sw_registration_id, |
| 207 const BackgroundSyncManager::BackgroundSyncRegistration& | 230 const BackgroundSyncManager::BackgroundSyncRegistration& |
| 208 sync_registration) { | 231 sync_registration) { |
| 209 bool was_called = false; | 232 bool was_called = false; |
| 210 background_sync_manager_->Register( | 233 background_sync_manager_->Register( |
| 211 GURL(kOrigin), sw_registration_id, sync_registration, | 234 sw_registration_id, sync_registration, |
| 212 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, | 235 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, |
| 213 base::Unretained(this), &was_called)); | 236 base::Unretained(this), &was_called)); |
| 214 base::RunLoop().RunUntilIdle(); | 237 base::RunLoop().RunUntilIdle(); |
| 215 EXPECT_TRUE(was_called); | 238 EXPECT_TRUE(was_called); |
| 216 return callback_error_ == BackgroundSyncManager::ERROR_TYPE_OK; | 239 return callback_error_ == BackgroundSyncManager::ERROR_TYPE_OK; |
| 217 } | 240 } |
| 218 | 241 |
| 219 bool Unregister(const BackgroundSyncManager::BackgroundSyncRegistration& | 242 bool Unregister(const BackgroundSyncManager::BackgroundSyncRegistration& |
| 220 sync_registration) { | 243 sync_registration) { |
| 221 return UnregisterWithServiceWorkerId(sw_registration_id_1_, | 244 return UnregisterWithServiceWorkerId(sw_registration_id_1_, |
| 222 sync_registration); | 245 sync_registration); |
| 223 } | 246 } |
| 224 | 247 |
| 225 bool UnregisterWithServiceWorkerId( | 248 bool UnregisterWithServiceWorkerId( |
| 226 int64 sw_registration_id, | 249 int64 sw_registration_id, |
| 227 const BackgroundSyncManager::BackgroundSyncRegistration& | 250 const BackgroundSyncManager::BackgroundSyncRegistration& |
| 228 sync_registration) { | 251 sync_registration) { |
| 229 bool was_called = false; | 252 bool was_called = false; |
| 230 background_sync_manager_->Unregister( | 253 background_sync_manager_->Unregister( |
| 231 GURL(kOrigin), sw_registration_id, sync_registration.tag, | 254 sw_registration_id, sync_registration.tag, |
| 232 sync_registration.periodicity, sync_registration.id, | 255 sync_registration.periodicity, sync_registration.id, |
| 233 base::Bind(&BackgroundSyncManagerTest::StatusCallback, | 256 base::Bind(&BackgroundSyncManagerTest::StatusCallback, |
| 234 base::Unretained(this), &was_called)); | 257 base::Unretained(this), &was_called)); |
| 235 base::RunLoop().RunUntilIdle(); | 258 base::RunLoop().RunUntilIdle(); |
| 236 EXPECT_TRUE(was_called); | 259 EXPECT_TRUE(was_called); |
| 237 return callback_error_ == BackgroundSyncManager::ERROR_TYPE_OK; | 260 return callback_error_ == BackgroundSyncManager::ERROR_TYPE_OK; |
| 238 } | 261 } |
| 239 | 262 |
| 240 bool GetRegistration(const BackgroundSyncManager::BackgroundSyncRegistration& | 263 bool GetRegistration(const BackgroundSyncManager::BackgroundSyncRegistration& |
| 241 sync_registration) { | 264 sync_registration) { |
| 242 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_, | 265 return GetRegistrationWithServiceWorkerId(sw_registration_id_1_, |
| 243 sync_registration); | 266 sync_registration); |
| 244 } | 267 } |
| 245 | 268 |
| 246 bool GetRegistrationWithServiceWorkerId( | 269 bool GetRegistrationWithServiceWorkerId( |
| 247 int64 sw_registration_id, | 270 int64 sw_registration_id, |
| 248 const BackgroundSyncManager::BackgroundSyncRegistration& | 271 const BackgroundSyncManager::BackgroundSyncRegistration& |
| 249 sync_registration) { | 272 sync_registration) { |
| 250 bool was_called = false; | 273 bool was_called = false; |
| 251 background_sync_manager_->GetRegistration( | 274 background_sync_manager_->GetRegistration( |
| 252 GURL(kOrigin), sw_registration_id, sync_registration.tag, | 275 sw_registration_id, sync_registration.tag, |
| 253 sync_registration.periodicity, | 276 sync_registration.periodicity, |
| 254 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, | 277 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, |
| 255 base::Unretained(this), &was_called)); | 278 base::Unretained(this), &was_called)); |
| 256 base::RunLoop().RunUntilIdle(); | 279 base::RunLoop().RunUntilIdle(); |
| 257 EXPECT_TRUE(was_called); | 280 EXPECT_TRUE(was_called); |
| 258 | 281 |
| 259 if (callback_error_ == BackgroundSyncManager::ERROR_TYPE_OK) { | 282 if (callback_error_ == BackgroundSyncManager::ERROR_TYPE_OK) { |
| 260 EXPECT_STREQ(sync_registration.tag.c_str(), | 283 EXPECT_STREQ(sync_registration.tag.c_str(), |
| 261 callback_registration_.tag.c_str()); | 284 callback_registration_.tag.c_str()); |
| 262 } | 285 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 282 sw_id == sw_registration_id_2_); | 305 sw_id == sw_registration_id_2_); |
| 283 return sw_id == sw_registration_id_1_ ? GURL(kPattern1) : GURL(kPattern2); | 306 return sw_id == sw_registration_id_1_ ? GURL(kPattern1) : GURL(kPattern2); |
| 284 } | 307 } |
| 285 | 308 |
| 286 TestBrowserThreadBundle browser_thread_bundle_; | 309 TestBrowserThreadBundle browser_thread_bundle_; |
| 287 scoped_ptr<EmbeddedWorkerTestHelper> helper_; | 310 scoped_ptr<EmbeddedWorkerTestHelper> helper_; |
| 288 scoped_ptr<BackgroundSyncManager> background_sync_manager_; | 311 scoped_ptr<BackgroundSyncManager> background_sync_manager_; |
| 289 | 312 |
| 290 int64 sw_registration_id_1_; | 313 int64 sw_registration_id_1_; |
| 291 int64 sw_registration_id_2_; | 314 int64 sw_registration_id_2_; |
| 315 scoped_refptr<ServiceWorkerRegistration> sw_registration_1_; | |
| 316 scoped_refptr<ServiceWorkerRegistration> sw_registration_2_; | |
| 292 | 317 |
| 293 BackgroundSyncManager::BackgroundSyncRegistration sync_reg_1_; | 318 BackgroundSyncManager::BackgroundSyncRegistration sync_reg_1_; |
| 294 BackgroundSyncManager::BackgroundSyncRegistration sync_reg_2_; | 319 BackgroundSyncManager::BackgroundSyncRegistration sync_reg_2_; |
| 295 | 320 |
| 296 // Callback values. | 321 // Callback values. |
| 297 BackgroundSyncManager::ErrorType callback_error_; | 322 BackgroundSyncManager::ErrorType callback_error_; |
| 298 BackgroundSyncManager::BackgroundSyncRegistration callback_registration_; | 323 BackgroundSyncManager::BackgroundSyncRegistration callback_registration_; |
| 299 ServiceWorkerStatusCode callback_sw_status_code_; | 324 ServiceWorkerStatusCode callback_sw_status_code_; |
| 300 }; | 325 }; |
| 301 | 326 |
| 302 TEST_F(BackgroundSyncManagerTest, Register) { | 327 TEST_F(BackgroundSyncManagerTest, Register) { |
| 303 EXPECT_TRUE(Register(sync_reg_1_)); | 328 EXPECT_TRUE(Register(sync_reg_1_)); |
| 304 } | 329 } |
| 305 | 330 |
| 306 TEST_F(BackgroundSyncManagerTest, RegistractionIntact) { | 331 TEST_F(BackgroundSyncManagerTest, RegistractionIntact) { |
| 307 EXPECT_TRUE(Register(sync_reg_1_)); | 332 EXPECT_TRUE(Register(sync_reg_1_)); |
| 308 EXPECT_STREQ(sync_reg_1_.tag.c_str(), callback_registration_.tag.c_str()); | 333 EXPECT_STREQ(sync_reg_1_.tag.c_str(), callback_registration_.tag.c_str()); |
| 309 EXPECT_NE( | 334 EXPECT_NE( |
| 310 BackgroundSyncManager::BackgroundSyncRegistration::kInvalidRegistrationId, | 335 BackgroundSyncManager::BackgroundSyncRegistration::kInvalidRegistrationId, |
| 311 callback_registration_.id); | 336 callback_registration_.id); |
| 312 } | 337 } |
| 313 | 338 |
| 339 TEST_F(BackgroundSyncManagerTest, RegisterWithoutLiveSWRegistration) { | |
| 340 sw_registration_1_ = nullptr; | |
| 341 EXPECT_FALSE(Register(sync_reg_1_)); | |
| 342 EXPECT_EQ(BackgroundSyncManager::ERROR_TYPE_NO_SERVICE_WORKER, | |
| 343 callback_error_); | |
| 344 } | |
| 345 | |
| 346 TEST_F(BackgroundSyncManagerTest, RegisterWithoutActiveSWRegistration) { | |
| 347 sw_registration_1_->UnsetVersion(sw_registration_1_->active_version()); | |
| 348 EXPECT_FALSE(Register(sync_reg_1_)); | |
| 349 EXPECT_EQ(BackgroundSyncManager::ERROR_TYPE_NO_SERVICE_WORKER, | |
| 350 callback_error_); | |
| 351 } | |
| 352 | |
| 314 TEST_F(BackgroundSyncManagerTest, RegisterExistingKeepsId) { | 353 TEST_F(BackgroundSyncManagerTest, RegisterExistingKeepsId) { |
| 315 EXPECT_TRUE(Register(sync_reg_1_)); | 354 EXPECT_TRUE(Register(sync_reg_1_)); |
| 316 BackgroundSyncManager::BackgroundSyncRegistration first_registration = | 355 BackgroundSyncManager::BackgroundSyncRegistration first_registration = |
| 317 callback_registration_; | 356 callback_registration_; |
| 318 EXPECT_TRUE(Register(sync_reg_1_)); | 357 EXPECT_TRUE(Register(sync_reg_1_)); |
| 319 EXPECT_TRUE(callback_registration_.Equals(first_registration)); | 358 EXPECT_TRUE(callback_registration_.Equals(first_registration)); |
| 320 EXPECT_EQ(first_registration.id, callback_registration_.id); | 359 EXPECT_EQ(first_registration.id, callback_registration_.id); |
| 321 } | 360 } |
| 322 | 361 |
| 323 TEST_F(BackgroundSyncManagerTest, RegisterOverwrites) { | 362 TEST_F(BackgroundSyncManagerTest, RegisterOverwrites) { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 500 manager->set_delay_backend(true); | 539 manager->set_delay_backend(true); |
| 501 manager->DoInit(); | 540 manager->DoInit(); |
| 502 | 541 |
| 503 const int64 kExpectedInitialId = | 542 const int64 kExpectedInitialId = |
| 504 BackgroundSyncManager::BackgroundSyncRegistration::kInitialId; | 543 BackgroundSyncManager::BackgroundSyncRegistration::kInitialId; |
| 505 | 544 |
| 506 bool register_called = false; | 545 bool register_called = false; |
| 507 bool unregister_called = false; | 546 bool unregister_called = false; |
| 508 bool get_registration_called = false; | 547 bool get_registration_called = false; |
| 509 manager->Register( | 548 manager->Register( |
| 510 GURL(kOrigin), sw_registration_id_1_, sync_reg_1_, | 549 sw_registration_id_1_, sync_reg_1_, |
| 511 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, | 550 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, |
| 512 base::Unretained(this), ®ister_called)); | 551 base::Unretained(this), ®ister_called)); |
| 513 manager->Unregister(GURL(kOrigin), sw_registration_id_1_, sync_reg_1_.tag, | 552 manager->Unregister(sw_registration_id_1_, sync_reg_1_.tag, |
| 514 sync_reg_1_.periodicity, kExpectedInitialId, | 553 sync_reg_1_.periodicity, kExpectedInitialId, |
| 515 base::Bind(&BackgroundSyncManagerTest::StatusCallback, | 554 base::Bind(&BackgroundSyncManagerTest::StatusCallback, |
| 516 base::Unretained(this), &unregister_called)); | 555 base::Unretained(this), &unregister_called)); |
| 517 manager->GetRegistration( | 556 manager->GetRegistration( |
| 518 GURL(kOrigin), sw_registration_id_1_, sync_reg_1_.tag, | 557 sw_registration_id_1_, sync_reg_1_.tag, sync_reg_1_.periodicity, |
| 519 sync_reg_1_.periodicity, | |
| 520 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, | 558 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, |
| 521 base::Unretained(this), &get_registration_called)); | 559 base::Unretained(this), &get_registration_called)); |
| 522 | 560 |
| 523 base::RunLoop().RunUntilIdle(); | 561 base::RunLoop().RunUntilIdle(); |
| 524 // Init should be blocked while loading from the backend. | 562 // Init should be blocked while loading from the backend. |
| 525 EXPECT_FALSE(register_called); | 563 EXPECT_FALSE(register_called); |
| 526 EXPECT_FALSE(unregister_called); | 564 EXPECT_FALSE(unregister_called); |
| 527 EXPECT_FALSE(get_registration_called); | 565 EXPECT_FALSE(get_registration_called); |
| 528 | 566 |
| 529 manager->Continue(); | 567 manager->Continue(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 562 TestBackgroundSyncManager* manager = | 600 TestBackgroundSyncManager* manager = |
| 563 new TestBackgroundSyncManager(helper_->context_wrapper()); | 601 new TestBackgroundSyncManager(helper_->context_wrapper()); |
| 564 background_sync_manager_.reset(manager); | 602 background_sync_manager_.reset(manager); |
| 565 manager->DoInit(); | 603 manager->DoInit(); |
| 566 | 604 |
| 567 EXPECT_TRUE(Register(sync_reg_1_)); | 605 EXPECT_TRUE(Register(sync_reg_1_)); |
| 568 | 606 |
| 569 manager->set_delay_backend(true); | 607 manager->set_delay_backend(true); |
| 570 bool callback_called = false; | 608 bool callback_called = false; |
| 571 manager->Register( | 609 manager->Register( |
| 572 GURL(kOrigin), sw_registration_id_1_, sync_reg_2_, | 610 sw_registration_id_1_, sync_reg_2_, |
| 573 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, | 611 base::Bind(&BackgroundSyncManagerTest::StatusAndRegistrationCallback, |
| 574 base::Unretained(this), &callback_called)); | 612 base::Unretained(this), &callback_called)); |
| 575 | 613 |
| 576 base::RunLoop().RunUntilIdle(); | 614 base::RunLoop().RunUntilIdle(); |
| 577 EXPECT_FALSE(callback_called); | 615 EXPECT_FALSE(callback_called); |
| 578 UnregisterServiceWorker(sw_registration_id_1_); | 616 UnregisterServiceWorker(sw_registration_id_1_); |
| 579 | 617 |
| 580 manager->Continue(); | 618 manager->Continue(); |
| 581 base::RunLoop().RunUntilIdle(); | 619 base::RunLoop().RunUntilIdle(); |
| 582 EXPECT_TRUE(callback_called); | 620 EXPECT_TRUE(callback_called); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 EXPECT_TRUE(Register(sync_reg_1_)); | 661 EXPECT_TRUE(Register(sync_reg_1_)); |
| 624 manager->set_corrupt_backend(true); | 662 manager->set_corrupt_backend(true); |
| 625 EXPECT_FALSE(Register(sync_reg_2_)); | 663 EXPECT_FALSE(Register(sync_reg_2_)); |
| 626 | 664 |
| 627 // The manager is now disabled and not accepting new requests until browser | 665 // The manager is now disabled and not accepting new requests until browser |
| 628 // restart or notification that the storage has been wiped. | 666 // restart or notification that the storage has been wiped. |
| 629 manager->set_corrupt_backend(false); | 667 manager->set_corrupt_backend(false); |
| 630 helper_->context()->ScheduleDeleteAndStartOver(); | 668 helper_->context()->ScheduleDeleteAndStartOver(); |
| 631 base::RunLoop().RunUntilIdle(); | 669 base::RunLoop().RunUntilIdle(); |
| 632 | 670 |
| 633 bool called = false; | 671 RegisterServiceWorkers(); |
| 634 helper_->context()->RegisterServiceWorker( | |
| 635 GURL(kPattern1), GURL(kScript1), NULL, | |
| 636 base::Bind(&RegisterServiceWorkerCallback, &called, | |
| 637 &sw_registration_id_1_)); | |
| 638 base::RunLoop().RunUntilIdle(); | |
| 639 EXPECT_TRUE(called); | |
| 640 | 672 |
| 641 EXPECT_TRUE(Register(sync_reg_2_)); | 673 EXPECT_TRUE(Register(sync_reg_2_)); |
| 642 EXPECT_FALSE(GetRegistration(sync_reg_1_)); | 674 EXPECT_FALSE(GetRegistration(sync_reg_1_)); |
| 643 EXPECT_TRUE(GetRegistration(sync_reg_2_)); | 675 EXPECT_TRUE(GetRegistration(sync_reg_2_)); |
| 644 } | 676 } |
| 645 | 677 |
| 646 TEST_F(BackgroundSyncManagerTest, RegistrationEqualsId) { | 678 TEST_F(BackgroundSyncManagerTest, RegistrationEqualsId) { |
| 647 BackgroundSyncManager::BackgroundSyncRegistration reg_1; | 679 BackgroundSyncManager::BackgroundSyncRegistration reg_1; |
| 648 BackgroundSyncManager::BackgroundSyncRegistration reg_2; | 680 BackgroundSyncManager::BackgroundSyncRegistration reg_2; |
| 649 | 681 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 EXPECT_TRUE(Unregister(callback_registration_)); | 779 EXPECT_TRUE(Unregister(callback_registration_)); |
| 748 EXPECT_FALSE(GetRegistration(sync_reg_1_)); | 780 EXPECT_FALSE(GetRegistration(sync_reg_1_)); |
| 749 EXPECT_TRUE(GetRegistration(sync_reg_2_)); | 781 EXPECT_TRUE(GetRegistration(sync_reg_2_)); |
| 750 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.periodicity); | 782 EXPECT_EQ(SYNC_ONE_SHOT, callback_registration_.periodicity); |
| 751 | 783 |
| 752 EXPECT_TRUE(Unregister(callback_registration_)); | 784 EXPECT_TRUE(Unregister(callback_registration_)); |
| 753 EXPECT_FALSE(GetRegistration(sync_reg_2_)); | 785 EXPECT_FALSE(GetRegistration(sync_reg_2_)); |
| 754 } | 786 } |
| 755 | 787 |
| 756 } // namespace content | 788 } // namespace content |
| OLD | NEW |