Chromium Code Reviews| Index: content/browser/service_worker/service_worker_job_unittest.cc |
| diff --git a/content/browser/service_worker/service_worker_job_unittest.cc b/content/browser/service_worker/service_worker_job_unittest.cc |
| index a458affba8bdeee2fbc49e1c0734e0fae6f9022c..16440c599fe34f744883ee4d914d0bebec050996 100644 |
| --- a/content/browser/service_worker/service_worker_job_unittest.cc |
| +++ b/content/browser/service_worker/service_worker_job_unittest.cc |
| @@ -6,10 +6,14 @@ |
| #include "base/logging.h" |
| #include "base/run_loop.h" |
| #include "content/browser/browser_thread_impl.h" |
| +#include "content/browser/service_worker/embedded_worker_registry.h" |
| +#include "content/browser/service_worker/embedded_worker_test_helper.h" |
| +#include "content/browser/service_worker/service_worker_context_core.h" |
| #include "content/browser/service_worker/service_worker_job_coordinator.h" |
| #include "content/browser/service_worker/service_worker_registration.h" |
| #include "content/browser/service_worker/service_worker_registration_status.h" |
| #include "content/public/test/test_browser_thread_bundle.h" |
| +#include "ipc/ipc_test_sink.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| // Unit tests for testing all job registration tasks. |
| @@ -91,16 +95,35 @@ class ServiceWorkerJobTest : public testing::Test { |
| : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} |
| virtual void SetUp() OVERRIDE { |
| + context_.reset(new ServiceWorkerContextCore(base::FilePath(), NULL)); |
| + helper_.reset(new EmbeddedWorkerTestHelper(context_.get())); |
| + |
| storage_.reset(new ServiceWorkerStorage(base::FilePath(), NULL)); |
| - job_coordinator_.reset(new ServiceWorkerJobCoordinator(storage_.get())); |
| + embedded_worker_registry_ = |
| + new EmbeddedWorkerRegistry(base::WeakPtr<ServiceWorkerContextCore>()); |
| + job_coordinator_.reset(new ServiceWorkerJobCoordinator( |
| + storage_.get(), embedded_worker_registry_)); |
| + |
| + render_process_id_ = 88; |
| + embedded_worker_registry_->AddChildProcessSender(render_process_id_, |
| + &sink_); |
|
kinuko
2014/01/29 09:56:20
Some lines (setting up its own registry etc) seem
alecflett
2014/01/30 01:51:13
yep sorry I didn't mean you had to review this one
|
| } |
| - virtual void TearDown() OVERRIDE { storage_.reset(); } |
| + virtual void TearDown() OVERRIDE { |
| + storage_.reset(); |
| + helper_.reset(); |
| + context_.reset(); |
| + } |
| protected: |
| TestBrowserThreadBundle browser_thread_bundle_; |
| + IPC::TestSink sink_; |
| scoped_ptr<ServiceWorkerStorage> storage_; |
| scoped_ptr<ServiceWorkerJobCoordinator> job_coordinator_; |
| + scoped_refptr<EmbeddedWorkerRegistry> embedded_worker_registry_; |
| + scoped_ptr<ServiceWorkerContextCore> context_; |
| + scoped_ptr<EmbeddedWorkerTestHelper> helper_; |
| + int render_process_id_; |
| }; |
| TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) { |
| @@ -109,6 +132,7 @@ TEST_F(ServiceWorkerJobTest, SameDocumentSameRegistration) { |
| job_coordinator_->Register( |
| GURL("http://www.example.com/*"), |
| GURL("http://www.example.com/service_worker.js"), |
| + render_process_id_, |
| SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration)); |
| EXPECT_FALSE(called); |
| base::RunLoop().RunUntilIdle(); |
| @@ -141,6 +165,7 @@ TEST_F(ServiceWorkerJobTest, SameMatchSameRegistration) { |
| job_coordinator_->Register( |
| GURL("http://www.example.com/*"), |
| GURL("http://www.example.com/service_worker.js"), |
| + render_process_id_, |
| SaveRegistration(SERVICE_WORKER_OK, &called, &original_registration)); |
| EXPECT_FALSE(called); |
| base::RunLoop().RunUntilIdle(); |
| @@ -174,6 +199,7 @@ TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) { |
| job_coordinator_->Register( |
| GURL("http://www.example.com/one/*"), |
| GURL("http://www.example.com/service_worker.js"), |
| + render_process_id_, |
| SaveRegistration(SERVICE_WORKER_OK, &called1, &original_registration1)); |
| bool called2; |
| @@ -181,6 +207,7 @@ TEST_F(ServiceWorkerJobTest, DifferentMatchDifferentRegistration) { |
| job_coordinator_->Register( |
| GURL("http://www.example.com/two/*"), |
| GURL("http://www.example.com/service_worker.js"), |
| + render_process_id_, |
| SaveRegistration(SERVICE_WORKER_OK, &called2, &original_registration2)); |
| EXPECT_FALSE(called1); |
| @@ -214,6 +241,7 @@ TEST_F(ServiceWorkerJobTest, Register) { |
| job_coordinator_->Register( |
| GURL("http://www.example.com/*"), |
| GURL("http://www.example.com/service_worker.js"), |
| + render_process_id_, |
| SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
| ASSERT_FALSE(called); |
| @@ -232,6 +260,7 @@ TEST_F(ServiceWorkerJobTest, Unregister) { |
| job_coordinator_->Register( |
| pattern, |
| GURL("http://www.example.com/service_worker.js"), |
| + render_process_id_, |
| SaveRegistration(SERVICE_WORKER_OK, &called, ®istration)); |
| ASSERT_FALSE(called); |
| @@ -239,6 +268,7 @@ TEST_F(ServiceWorkerJobTest, Unregister) { |
| ASSERT_TRUE(called); |
| job_coordinator_->Unregister(pattern, |
| + render_process_id_, |
| SaveUnregistration(SERVICE_WORKER_OK, &called)); |
| ASSERT_FALSE(called); |
| @@ -268,6 +298,7 @@ TEST_F(ServiceWorkerJobTest, RegisterNewScript) { |
| job_coordinator_->Register( |
| pattern, |
| GURL("http://www.example.com/service_worker.js"), |
| + render_process_id_, |
| SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration)); |
| ASSERT_FALSE(called); |
| @@ -291,6 +322,7 @@ TEST_F(ServiceWorkerJobTest, RegisterNewScript) { |
| job_coordinator_->Register( |
| pattern, |
| GURL("http://www.example.com/service_worker_new.js"), |
| + render_process_id_, |
| SaveRegistration(SERVICE_WORKER_OK, &called, &new_registration)); |
| ASSERT_FALSE(called); |
| @@ -325,6 +357,7 @@ TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) { |
| job_coordinator_->Register( |
| pattern, |
| script_url, |
| + render_process_id_, |
| SaveRegistration(SERVICE_WORKER_OK, &called, &old_registration)); |
| ASSERT_FALSE(called); |
| @@ -346,6 +379,7 @@ TEST_F(ServiceWorkerJobTest, RegisterDuplicateScript) { |
| job_coordinator_->Register( |
| pattern, |
| script_url, |
| + render_process_id_, |
| SaveRegistration(SERVICE_WORKER_OK, &called, &new_registration)); |
| ASSERT_FALSE(called); |
| @@ -380,11 +414,14 @@ TEST_F(ServiceWorkerJobTest, ParallelRegUnreg) { |
| job_coordinator_->Register( |
| pattern, |
| script_url, |
| + render_process_id_, |
| SaveRegistration(SERVICE_WORKER_OK, ®istration_called, ®istration)); |
| bool unregistration_called = false; |
| job_coordinator_->Unregister( |
| - pattern, SaveUnregistration(SERVICE_WORKER_OK, &unregistration_called)); |
| + pattern, |
| + render_process_id_, |
| + SaveUnregistration(SERVICE_WORKER_OK, &unregistration_called)); |
| ASSERT_FALSE(registration_called); |
| ASSERT_FALSE(unregistration_called); |
| @@ -417,8 +454,9 @@ TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) { |
| job_coordinator_->Register( |
| pattern, |
| script_url1, |
| - SaveRegistration(SERVICE_WORKER_OK, ®istration1_called, |
| - ®istration1)); |
| + render_process_id_, |
| + SaveRegistration( |
| + SERVICE_WORKER_OK, ®istration1_called, ®istration1)); |
| GURL script_url2("http://www.example.com/service_worker2.js"); |
| bool registration2_called = false; |
| @@ -426,8 +464,9 @@ TEST_F(ServiceWorkerJobTest, ParallelRegNewScript) { |
| job_coordinator_->Register( |
| pattern, |
| script_url2, |
| - SaveRegistration(SERVICE_WORKER_OK, ®istration2_called, |
| - ®istration2)); |
| + render_process_id_, |
| + SaveRegistration( |
| + SERVICE_WORKER_OK, ®istration2_called, ®istration2)); |
| ASSERT_FALSE(registration1_called); |
| ASSERT_FALSE(registration2_called); |
| @@ -461,16 +500,18 @@ TEST_F(ServiceWorkerJobTest, ParallelRegSameScript) { |
| job_coordinator_->Register( |
| pattern, |
| script_url, |
| - SaveRegistration(SERVICE_WORKER_OK, ®istration1_called, |
| - ®istration1)); |
| + render_process_id_, |
| + SaveRegistration( |
| + SERVICE_WORKER_OK, ®istration1_called, ®istration1)); |
| bool registration2_called = false; |
| scoped_refptr<ServiceWorkerRegistration> registration2; |
| job_coordinator_->Register( |
| pattern, |
| script_url, |
| - SaveRegistration(SERVICE_WORKER_OK, ®istration2_called, |
| - ®istration2)); |
| + render_process_id_, |
| + SaveRegistration( |
| + SERVICE_WORKER_OK, ®istration2_called, ®istration2)); |
| ASSERT_FALSE(registration1_called); |
| ASSERT_FALSE(registration2_called); |
| @@ -498,11 +539,15 @@ TEST_F(ServiceWorkerJobTest, ParallelUnreg) { |
| GURL script_url("http://www.example.com/service_worker.js"); |
| bool unregistration1_called = false; |
| job_coordinator_->Unregister( |
| - pattern, SaveUnregistration(SERVICE_WORKER_OK, &unregistration1_called)); |
| + pattern, |
| + render_process_id_, |
| + SaveUnregistration(SERVICE_WORKER_OK, &unregistration1_called)); |
| bool unregistration2_called = false; |
| job_coordinator_->Unregister( |
| - pattern, SaveUnregistration(SERVICE_WORKER_OK, &unregistration2_called)); |
| + pattern, |
| + render_process_id_, |
| + SaveUnregistration(SERVICE_WORKER_OK, &unregistration2_called)); |
| ASSERT_FALSE(unregistration1_called); |
| ASSERT_FALSE(unregistration2_called); |