| 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 e7c230f93a0093655a63bb8c8d375ab9ea41f7d0..583fae3dc31199ea52e90e3ff490dfba89ef73c3 100644
|
| --- a/content/browser/service_worker/service_worker_context_unittest.cc
|
| +++ b/content/browser/service_worker/service_worker_context_unittest.cc
|
| @@ -8,10 +8,12 @@
|
| #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/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 {
|
| @@ -50,13 +52,41 @@ class ServiceWorkerContextTest : public testing::Test {
|
|
|
| virtual void SetUp() OVERRIDE {
|
| context_.reset(new ServiceWorkerContextCore(base::FilePath(), NULL));
|
| +
|
| + int provider_id = 123;
|
| + render_process_id_ = 99;
|
| + context_->embedded_worker_registry()->AddChildProcessSender(
|
| + render_process_id_, &sink_);
|
| + scoped_ptr<ServiceWorkerProviderHost> provider_host(
|
| + new ServiceWorkerProviderHost(render_process_id_, provider_id));
|
| + context_->AddProviderHost(provider_host.Pass());
|
| +
|
| + provider_host_ = context_->GetProviderHost(render_process_id_, provider_id);
|
| + }
|
| +
|
| + virtual void TearDown() OVERRIDE {
|
| + context_.reset();
|
| + context_->embedded_worker_registry()->RemoveChildProcessSender(
|
| + provider_host_->process_id());
|
| + context_->RemoveProviderHost(provider_host_->process_id(),
|
| + provider_host_->provider_id());
|
| }
|
|
|
| - virtual void TearDown() OVERRIDE { context_.reset(); }
|
| + int GetWorkerInstanceId() {
|
| + EXPECT_EQ(1U,
|
| + context_->embedded_worker_registry()->worker_instances().size());
|
| + return context_->embedded_worker_registry()
|
| + ->worker_instances()
|
| + .begin()
|
| + ->first;
|
| + }
|
|
|
| protected:
|
| TestBrowserThreadBundle browser_thread_bundle_;
|
| + IPC::TestSink sink_;
|
| scoped_ptr<ServiceWorkerContextCore> context_;
|
| + ServiceWorkerProviderHost* provider_host_;
|
| + int render_process_id_;
|
| };
|
|
|
| void RegistrationCallback(
|
| @@ -72,13 +102,21 @@ TEST_F(ServiceWorkerContextTest, Register) {
|
| context_->RegisterServiceWorker(
|
| GURL("http://www.example.com/*"),
|
| GURL("http://www.example.com/service_worker.js"),
|
| + provider_host_,
|
| MakeRegisteredCallback(&called, ®istration_id));
|
|
|
| + LOG(ERROR) << "RunUntilIdle...";
|
| ASSERT_FALSE(called);
|
| base::RunLoop().RunUntilIdle();
|
| - ASSERT_TRUE(called);
|
|
|
| - ASSERT_NE(-1L, registration_id);
|
| + EXPECT_EQ(1UL, sink_.message_count());
|
| +
|
| + LOG(ERROR) << "Claiming that OnWorkerStarted()";
|
| + context_->embedded_worker_registry()->OnWorkerStarted(
|
| + render_process_id_, -1, GetWorkerInstanceId());
|
| + EXPECT_TRUE(called);
|
| +
|
| + EXPECT_NE(-1L, registration_id);
|
| }
|
|
|
| // Make sure registrations are cleaned up when they are unregistered.
|
| @@ -90,6 +128,7 @@ TEST_F(ServiceWorkerContextTest, Unregister) {
|
| context_->RegisterServiceWorker(
|
| pattern,
|
| GURL("http://www.example.com/service_worker.js"),
|
| + provider_host_,
|
| MakeRegisteredCallback(&called, ®istration_id));
|
|
|
| ASSERT_FALSE(called);
|
| @@ -97,7 +136,8 @@ TEST_F(ServiceWorkerContextTest, Unregister) {
|
| ASSERT_TRUE(called);
|
|
|
| called = false;
|
| - context_->UnregisterServiceWorker(pattern, MakeUnregisteredCallback(&called));
|
| + context_->UnregisterServiceWorker(
|
| + pattern, provider_host_, MakeUnregisteredCallback(&called));
|
|
|
| ASSERT_FALSE(called);
|
| base::RunLoop().RunUntilIdle();
|
| @@ -114,6 +154,7 @@ TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
|
| context_->RegisterServiceWorker(
|
| pattern,
|
| GURL("http://www.example.com/service_worker.js"),
|
| + provider_host_,
|
| MakeRegisteredCallback(&called, &old_registration_id));
|
|
|
| ASSERT_FALSE(called);
|
| @@ -125,6 +166,7 @@ TEST_F(ServiceWorkerContextTest, RegisterNewScript) {
|
| context_->RegisterServiceWorker(
|
| pattern,
|
| GURL("http://www.example.com/service_worker_new.js"),
|
| + provider_host_,
|
| MakeRegisteredCallback(&called, &new_registration_id));
|
|
|
| ASSERT_FALSE(called);
|
| @@ -145,6 +187,7 @@ TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) {
|
| context_->RegisterServiceWorker(
|
| pattern,
|
| script_url,
|
| + provider_host_,
|
| MakeRegisteredCallback(&called, &old_registration_id));
|
|
|
| ASSERT_FALSE(called);
|
| @@ -156,6 +199,7 @@ TEST_F(ServiceWorkerContextTest, RegisterDuplicateScript) {
|
| context_->RegisterServiceWorker(
|
| pattern,
|
| script_url,
|
| + provider_host_,
|
| MakeRegisteredCallback(&called, &new_registration_id));
|
|
|
| ASSERT_FALSE(called);
|
|
|