| 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" |
| 11 #include "content/browser/service_worker/service_worker_context_core.h" | 11 #include "content/browser/service_worker/service_worker_context_core.h" |
| 12 #include "content/browser/service_worker/service_worker_job_coordinator.h" | 12 #include "content/browser/service_worker/service_worker_job_coordinator.h" |
| 13 #include "content/browser/service_worker/service_worker_registration.h" | 13 #include "content/browser/service_worker/service_worker_registration.h" |
| 14 #include "content/browser/service_worker/service_worker_registration_status.h" | 14 #include "content/browser/service_worker/service_worker_registration_status.h" |
| 15 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 16 #include "ipc/ipc_test_sink.h" | 16 #include "ipc/ipc_test_sink.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 // Unit tests for testing all job registration tasks. | 19 // Unit tests for testing all job registration tasks. |
| 20 namespace content { | 20 namespace content { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 void SaveRegistrationCallback( | 24 void SaveRegistrationCallback( |
| 25 ServiceWorkerStatusCode expected_status, | 25 ServiceWorkerStatusCode expected_status, |
| 26 bool* called, | 26 bool* called, |
| 27 scoped_refptr<ServiceWorkerRegistration>* registration, | 27 scoped_refptr<ServiceWorkerRegistration>* registration_out, |
| 28 ServiceWorkerStatusCode status, | 28 ServiceWorkerStatusCode status, |
| 29 ServiceWorkerVersion* result) { | 29 ServiceWorkerRegistration* registration, |
| 30 ServiceWorkerVersion* version) { |
| 31 ASSERT_TRUE(!version || version->registration_id() == registration->id()) |
| 32 << version << " " << registration; |
| 30 EXPECT_EQ(expected_status, status); | 33 EXPECT_EQ(expected_status, status); |
| 31 *called = true; | 34 *called = true; |
| 32 *registration = result ? result->registration() : NULL; | 35 *registration_out = registration; |
| 33 } | 36 } |
| 34 | 37 |
| 35 void SaveFoundRegistrationCallback( | 38 void SaveFoundRegistrationCallback( |
| 36 ServiceWorkerStatusCode expected_status, | 39 ServiceWorkerStatusCode expected_status, |
| 37 bool* called, | 40 bool* called, |
| 38 scoped_refptr<ServiceWorkerRegistration>* registration, | 41 scoped_refptr<ServiceWorkerRegistration>* registration, |
| 39 ServiceWorkerStatusCode status, | 42 ServiceWorkerStatusCode status, |
| 40 const scoped_refptr<ServiceWorkerRegistration>& result) { | 43 const scoped_refptr<ServiceWorkerRegistration>& result) { |
| 41 EXPECT_EQ(expected_status, status); | 44 EXPECT_EQ(expected_status, status); |
| 42 *called = true; | 45 *called = true; |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 pattern, | 449 pattern, |
| 447 render_process_id_, | 450 render_process_id_, |
| 448 SaveUnregistration(SERVICE_WORKER_OK, &unregistration_called)); | 451 SaveUnregistration(SERVICE_WORKER_OK, &unregistration_called)); |
| 449 | 452 |
| 450 ASSERT_FALSE(registration_called); | 453 ASSERT_FALSE(registration_called); |
| 451 ASSERT_FALSE(unregistration_called); | 454 ASSERT_FALSE(unregistration_called); |
| 452 base::RunLoop().RunUntilIdle(); | 455 base::RunLoop().RunUntilIdle(); |
| 453 ASSERT_TRUE(registration_called); | 456 ASSERT_TRUE(registration_called); |
| 454 ASSERT_TRUE(unregistration_called); | 457 ASSERT_TRUE(unregistration_called); |
| 455 | 458 |
| 456 ASSERT_TRUE(registration->is_shutdown()); | |
| 457 | |
| 458 bool find_called = false; | 459 bool find_called = false; |
| 459 storage()->FindRegistrationForPattern( | 460 storage()->FindRegistrationForPattern( |
| 460 pattern, | 461 pattern, |
| 461 SaveFoundRegistration( | 462 SaveFoundRegistration( |
| 462 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called, ®istration)); | 463 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called, ®istration)); |
| 463 | 464 |
| 464 base::RunLoop().RunUntilIdle(); | 465 base::RunLoop().RunUntilIdle(); |
| 465 | 466 |
| 466 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); | 467 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); |
| 467 } | 468 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 | 501 |
| 501 scoped_refptr<ServiceWorkerRegistration> registration; | 502 scoped_refptr<ServiceWorkerRegistration> registration; |
| 502 bool find_called = false; | 503 bool find_called = false; |
| 503 storage()->FindRegistrationForPattern( | 504 storage()->FindRegistrationForPattern( |
| 504 pattern, | 505 pattern, |
| 505 SaveFoundRegistration( | 506 SaveFoundRegistration( |
| 506 SERVICE_WORKER_OK, &find_called, ®istration)); | 507 SERVICE_WORKER_OK, &find_called, ®istration)); |
| 507 | 508 |
| 508 base::RunLoop().RunUntilIdle(); | 509 base::RunLoop().RunUntilIdle(); |
| 509 | 510 |
| 510 EXPECT_TRUE(registration1->is_shutdown()); | |
| 511 EXPECT_FALSE(registration2->is_shutdown()); | |
| 512 ASSERT_EQ(registration2, registration); | 511 ASSERT_EQ(registration2, registration); |
| 513 } | 512 } |
| 514 | 513 |
| 515 // Register the exact same pattern + script. Requests should be | 514 // Register the exact same pattern + script. Requests should be |
| 516 // coalesced such that both callers get the exact same registration | 515 // coalesced such that both callers get the exact same registration |
| 517 // object. | 516 // object. |
| 518 TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) { | 517 TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) { |
| 519 GURL pattern("http://www.example.com/*"); | 518 GURL pattern("http://www.example.com/*"); |
| 520 | 519 |
| 521 GURL script_url("http://www.example.com/service_worker1.js"); | 520 GURL script_url("http://www.example.com/service_worker1.js"); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 storage()->FindRegistrationForPattern( | 586 storage()->FindRegistrationForPattern( |
| 588 pattern, | 587 pattern, |
| 589 SaveFoundRegistration( | 588 SaveFoundRegistration( |
| 590 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called, ®istration)); | 589 SERVICE_WORKER_ERROR_NOT_FOUND, &find_called, ®istration)); |
| 591 | 590 |
| 592 base::RunLoop().RunUntilIdle(); | 591 base::RunLoop().RunUntilIdle(); |
| 593 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); | 592 ASSERT_EQ(scoped_refptr<ServiceWorkerRegistration>(), registration); |
| 594 } | 593 } |
| 595 | 594 |
| 596 } // namespace content | 595 } // namespace content |
| OLD | NEW |