| 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 "base/files/scoped_temp_dir.h" | 5 #include "base/files/scoped_temp_dir.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "content/browser/browser_thread_impl.h" | 8 #include "content/browser/browser_thread_impl.h" |
| 9 #include "content/browser/service_worker/embedded_worker_registry.h" | 9 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 10 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 10 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 pattern, | 238 pattern, |
| 239 GURL("http://www.example.com/service_worker.js"), | 239 GURL("http://www.example.com/service_worker.js"), |
| 240 render_process_id_, | 240 render_process_id_, |
| 241 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); | 241 SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
| 242 | 242 |
| 243 ASSERT_FALSE(called); | 243 ASSERT_FALSE(called); |
| 244 base::RunLoop().RunUntilIdle(); | 244 base::RunLoop().RunUntilIdle(); |
| 245 ASSERT_TRUE(called); | 245 ASSERT_TRUE(called); |
| 246 | 246 |
| 247 job_coordinator()->Unregister(pattern, | 247 job_coordinator()->Unregister(pattern, |
| 248 render_process_id_, | |
| 249 SaveUnregistration(SERVICE_WORKER_OK, &called)); | 248 SaveUnregistration(SERVICE_WORKER_OK, &called)); |
| 250 | 249 |
| 251 ASSERT_FALSE(called); | 250 ASSERT_FALSE(called); |
| 252 base::RunLoop().RunUntilIdle(); | 251 base::RunLoop().RunUntilIdle(); |
| 253 ASSERT_TRUE(called); | 252 ASSERT_TRUE(called); |
| 254 | 253 |
| 255 ASSERT_TRUE(registration->HasOneRef()); | 254 ASSERT_TRUE(registration->HasOneRef()); |
| 256 | 255 |
| 257 storage()->FindRegistrationForPattern( | 256 storage()->FindRegistrationForPattern( |
| 258 pattern, | 257 pattern, |
| 259 SaveFoundRegistration(SERVICE_WORKER_ERROR_NOT_FOUND, | 258 SaveFoundRegistration(SERVICE_WORKER_ERROR_NOT_FOUND, |
| 260 &called, ®istration)); | 259 &called, ®istration)); |
| 261 | 260 |
| 262 ASSERT_FALSE(called); | 261 ASSERT_FALSE(called); |
| 263 base::RunLoop().RunUntilIdle(); | 262 base::RunLoop().RunUntilIdle(); |
| 264 ASSERT_TRUE(called); | 263 ASSERT_TRUE(called); |
| 265 | 264 |
| 266 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); | 265 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(NULL), registration); |
| 267 } | 266 } |
| 268 | 267 |
| 269 TEST_F(ServiceWorkerJobTest, Unregister_NothingRegistered) { | 268 TEST_F(ServiceWorkerJobTest, Unregister_NothingRegistered) { |
| 270 GURL pattern("http://www.example.com/*"); | 269 GURL pattern("http://www.example.com/*"); |
| 271 | 270 |
| 272 bool called; | 271 bool called; |
| 273 job_coordinator()->Unregister(pattern, | 272 job_coordinator()->Unregister(pattern, |
| 274 render_process_id_, | |
| 275 SaveUnregistration(SERVICE_WORKER_OK, &called)); | 273 SaveUnregistration(SERVICE_WORKER_OK, &called)); |
| 276 | 274 |
| 277 ASSERT_FALSE(called); | 275 ASSERT_FALSE(called); |
| 278 base::RunLoop().RunUntilIdle(); | 276 base::RunLoop().RunUntilIdle(); |
| 279 ASSERT_TRUE(called); | 277 ASSERT_TRUE(called); |
| 280 } | 278 } |
| 281 | 279 |
| 282 // Make sure that when a new registration replaces an existing | 280 // Make sure that when a new registration replaces an existing |
| 283 // registration, that the old one is cleaned up. | 281 // registration, that the old one is cleaned up. |
| 284 TEST_F(ServiceWorkerJobTest, RegisterNewScript) { | 282 TEST_F(ServiceWorkerJobTest, RegisterNewScript) { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 scoped_refptr<ServiceWorkerRegistration> registration; | 436 scoped_refptr<ServiceWorkerRegistration> registration; |
| 439 job_coordinator()->Register( | 437 job_coordinator()->Register( |
| 440 pattern, | 438 pattern, |
| 441 script_url, | 439 script_url, |
| 442 render_process_id_, | 440 render_process_id_, |
| 443 SaveRegistration(SERVICE_WORKER_OK, ®istration_called, ®istration)); | 441 SaveRegistration(SERVICE_WORKER_OK, ®istration_called, ®istration)); |
| 444 | 442 |
| 445 bool unregistration_called = false; | 443 bool unregistration_called = false; |
| 446 job_coordinator()->Unregister( | 444 job_coordinator()->Unregister( |
| 447 pattern, | 445 pattern, |
| 448 render_process_id_, | |
| 449 SaveUnregistration(SERVICE_WORKER_OK, &unregistration_called)); | 446 SaveUnregistration(SERVICE_WORKER_OK, &unregistration_called)); |
| 450 | 447 |
| 451 ASSERT_FALSE(registration_called); | 448 ASSERT_FALSE(registration_called); |
| 452 ASSERT_FALSE(unregistration_called); | 449 ASSERT_FALSE(unregistration_called); |
| 453 base::RunLoop().RunUntilIdle(); | 450 base::RunLoop().RunUntilIdle(); |
| 454 ASSERT_TRUE(registration_called); | 451 ASSERT_TRUE(registration_called); |
| 455 ASSERT_TRUE(unregistration_called); | 452 ASSERT_TRUE(unregistration_called); |
| 456 | 453 |
| 457 bool find_called = false; | 454 bool find_called = false; |
| 458 storage()->FindRegistrationForPattern( | 455 storage()->FindRegistrationForPattern( |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 } | 551 } |
| 555 | 552 |
| 556 // Call simulataneous unregister calls. | 553 // Call simulataneous unregister calls. |
| 557 TEST_F(ServiceWorkerJobTest, ParallelUnreg) { | 554 TEST_F(ServiceWorkerJobTest, ParallelUnreg) { |
| 558 GURL pattern("http://www.example.com/*"); | 555 GURL pattern("http://www.example.com/*"); |
| 559 | 556 |
| 560 GURL script_url("http://www.example.com/service_worker.js"); | 557 GURL script_url("http://www.example.com/service_worker.js"); |
| 561 bool unregistration1_called = false; | 558 bool unregistration1_called = false; |
| 562 job_coordinator()->Unregister( | 559 job_coordinator()->Unregister( |
| 563 pattern, | 560 pattern, |
| 564 render_process_id_, | |
| 565 SaveUnregistration(SERVICE_WORKER_OK, &unregistration1_called)); | 561 SaveUnregistration(SERVICE_WORKER_OK, &unregistration1_called)); |
| 566 | 562 |
| 567 bool unregistration2_called = false; | 563 bool unregistration2_called = false; |
| 568 job_coordinator()->Unregister( | 564 job_coordinator()->Unregister( |
| 569 pattern, | 565 pattern, SaveUnregistration(SERVICE_WORKER_OK, &unregistration2_called)); |
| 570 render_process_id_, | |
| 571 SaveUnregistration(SERVICE_WORKER_OK, &unregistration2_called)); | |
| 572 | 566 |
| 573 ASSERT_FALSE(unregistration1_called); | 567 ASSERT_FALSE(unregistration1_called); |
| 574 ASSERT_FALSE(unregistration2_called); | 568 ASSERT_FALSE(unregistration2_called); |
| 575 base::RunLoop().RunUntilIdle(); | 569 base::RunLoop().RunUntilIdle(); |
| 576 ASSERT_TRUE(unregistration1_called); | 570 ASSERT_TRUE(unregistration1_called); |
| 577 ASSERT_TRUE(unregistration2_called); | 571 ASSERT_TRUE(unregistration2_called); |
| 578 | 572 |
| 579 // There isn't really a way to test that they are being coalesced, | 573 // There isn't really a way to test that they are being coalesced, |
| 580 // but we can make sure they can exist simultaneously without | 574 // but we can make sure they can exist simultaneously without |
| 581 // crashing. | 575 // crashing. |
| 582 scoped_refptr<ServiceWorkerRegistration> registration; | 576 scoped_refptr<ServiceWorkerRegistration> registration; |
| 583 bool find_called = false; | 577 bool find_called = false; |
| 584 storage()->FindRegistrationForPattern( | 578 storage()->FindRegistrationForPattern( |
| 585 pattern, | 579 pattern, |
| 586 SaveFoundRegistration( | 580 SaveFoundRegistration( |
| 587 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called, ®istration)); | 581 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called, ®istration)); |
| 588 | 582 |
| 589 base::RunLoop().RunUntilIdle(); | 583 base::RunLoop().RunUntilIdle(); |
| 590 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); | 584 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); |
| 591 } | 585 } |
| 592 | 586 |
| 593 } // namespace content | 587 } // namespace content |
| OLD | NEW |