Chromium Code Reviews| Index: content/browser/service_worker/service_worker_context_unittest.cc |
| diff --git a/content/browser/service_worker/service_worker_context_unittest.cc b/content/browser/service_worker/service_worker_context_unittest.cc |
| index 56f52188664ca5c9a0eabf82b42d373fcf43332d..67ba102943e8b2925a6a983112c483b0c3c186b0 100644 |
| --- a/content/browser/service_worker/service_worker_context_unittest.cc |
| +++ b/content/browser/service_worker/service_worker_context_unittest.cc |
| @@ -8,10 +8,13 @@ |
| #include "base/logging.h" |
| #include "base/message_loop/message_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_registration.h" |
| #include "content/public/test/test_browser_thread_bundle.h" |
| #include "content/public/test/test_utils.h" |
| +#include "ipc/ipc_test_sink.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace content { |
| @@ -22,6 +25,7 @@ void SaveResponseCallback(bool* called, |
| int64* store_result, |
| ServiceWorkerStatusCode status, |
| int64 result) { |
| + LOG(ERROR) << "SaveResponseCallback: " << status << ", " << result; |
| *called = true; |
| *store_result = result; |
| } |
| @@ -50,13 +54,26 @@ class ServiceWorkerContextTest : public testing::Test { |
| virtual void SetUp() OVERRIDE { |
| context_.reset(new ServiceWorkerContextCore(base::FilePath(), NULL)); |
| + helper_.reset(new EmbeddedWorkerTestHelper(context_.get())); |
| + scoped_ptr<EmbeddedWorkerInstance> worker = |
| + context_->embedded_worker_registry()->CreateWorker(); |
| + |
| + render_process_id_ = 99; |
| + embedded_worker_id_ = worker->embedded_worker_id(); |
|
kinuko
2014/01/29 09:56:20
These lines for embedded_worker_id_ are not necess
alecflett
2014/01/30 01:51:13
They are for the code as it is now - where StartWo
|
| + helper_->SimulateAddProcess(embedded_worker_id_, render_process_id_); |
| } |
| - virtual void TearDown() OVERRIDE { context_.reset(); } |
| + virtual void TearDown() OVERRIDE { |
| + helper_.reset(); |
| + context_.reset(); |
| + } |
| protected: |
| TestBrowserThreadBundle browser_thread_bundle_; |
| scoped_ptr<ServiceWorkerContextCore> context_; |
| + scoped_ptr<EmbeddedWorkerTestHelper> helper_; |
| + int render_process_id_; |
| + int embedded_worker_id_; |
| }; |
| void RegistrationCallback( |
| @@ -72,13 +89,16 @@ TEST_F(ServiceWorkerContextTest, Register) { |
| context_->RegisterServiceWorker( |
| GURL("http://www.example.com/*"), |
| GURL("http://www.example.com/service_worker.js"), |
| + render_process_id_, |
| MakeRegisteredCallback(&called, ®istration_id)); |
| + LOG(ERROR) << "RunUntilIdle..."; |
| ASSERT_FALSE(called); |
| base::RunLoop().RunUntilIdle(); |
| - ASSERT_TRUE(called); |
| + EXPECT_TRUE(called); |
| - ASSERT_NE(-1L, registration_id); |
| + EXPECT_EQ(1UL, helper_->ipc_sink()->message_count()); |
| + EXPECT_NE(-1L, registration_id); |
| } |
| // Make sure registrations are cleaned up when they are unregistered. |
| @@ -90,6 +110,7 @@ TEST_F(ServiceWorkerContextTest, Unregister) { |
| context_->RegisterServiceWorker( |
| pattern, |
| GURL("http://www.example.com/service_worker.js"), |
| + render_process_id_, |
| MakeRegisteredCallback(&called, ®istration_id)); |
| ASSERT_FALSE(called); |
| @@ -97,7 +118,8 @@ TEST_F(ServiceWorkerContextTest, Unregister) { |
| ASSERT_TRUE(called); |
| called = false; |
| - context_->UnregisterServiceWorker(pattern, MakeUnregisteredCallback(&called)); |
| + context_->UnregisterServiceWorker( |
| + pattern, render_process_id_, MakeUnregisteredCallback(&called)); |
| ASSERT_FALSE(called); |
| base::RunLoop().RunUntilIdle(); |
| @@ -114,6 +136,7 @@ TEST_F(ServiceWorkerContextTest, RegisterNewScript) { |
| context_->RegisterServiceWorker( |
| pattern, |
| GURL("http://www.example.com/service_worker.js"), |
| + render_process_id_, |
| MakeRegisteredCallback(&called, &old_registration_id)); |
| ASSERT_FALSE(called); |
| @@ -125,6 +148,7 @@ TEST_F(ServiceWorkerContextTest, RegisterNewScript) { |
| context_->RegisterServiceWorker( |
| pattern, |
| GURL("http://www.example.com/service_worker_new.js"), |
| + render_process_id_, |
| MakeRegisteredCallback(&called, &new_registration_id)); |
| ASSERT_FALSE(called); |
| @@ -145,6 +169,7 @@ TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) { |
| context_->RegisterServiceWorker( |
| pattern, |
| script_url, |
| + render_process_id_, |
| MakeRegisteredCallback(&called, &old_registration_id)); |
| ASSERT_FALSE(called); |
| @@ -156,6 +181,7 @@ TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) { |
| context_->RegisterServiceWorker( |
| pattern, |
| script_url, |
| + render_process_id_, |
| MakeRegisteredCallback(&called, &new_registration_id)); |
| ASSERT_FALSE(called); |