| Index: content/browser/service_worker/service_worker_provider_host_unittest.cc
|
| diff --git a/content/browser/service_worker/service_worker_provider_host_unittest.cc b/content/browser/service_worker/service_worker_provider_host_unittest.cc
|
| index 49dbfb15a5ab97fe2531a273f0eff33cc0a4bfb9..938b4acd0529497af3400d8ca9ad319182f27c6f 100644
|
| --- a/content/browser/service_worker/service_worker_provider_host_unittest.cc
|
| +++ b/content/browser/service_worker/service_worker_provider_host_unittest.cc
|
| @@ -4,8 +4,11 @@
|
|
|
| #include "base/basictypes.h"
|
| #include "base/memory/weak_ptr.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_context_wrapper.h"
|
| #include "content/browser/service_worker/service_worker_provider_host.h"
|
| +#include "content/browser/service_worker/service_worker_provider_host_registry.h"
|
| #include "content/browser/service_worker/service_worker_register_job.h"
|
| #include "content/browser/service_worker/service_worker_registration.h"
|
| #include "content/browser/service_worker/service_worker_version.h"
|
| @@ -23,48 +26,50 @@ class ServiceWorkerProviderHostTest : public testing::Test {
|
| virtual ~ServiceWorkerProviderHostTest() {}
|
|
|
| virtual void SetUp() OVERRIDE {
|
| - context_.reset(
|
| - new ServiceWorkerContextCore(base::FilePath(),
|
| - base::MessageLoopProxy::current(),
|
| - base::MessageLoopProxy::current(),
|
| - NULL,
|
| - NULL,
|
| - NULL));
|
| + helper_.reset(new EmbeddedWorkerTestHelper(kRenderProcessId));
|
|
|
| scope_ = GURL("http://www.example.com/*");
|
| script_url_ = GURL("http://www.example.com/service_worker.js");
|
| registration_ = new ServiceWorkerRegistration(
|
| - scope_, script_url_, 1L, context_->AsWeakPtr());
|
| + scope_, script_url_, 1L, context()->AsWeakPtr());
|
| version_ = new ServiceWorkerVersion(
|
| - registration_,
|
| - 1L, context_->AsWeakPtr());
|
| + registration_, 1L, context()->AsWeakPtr());
|
|
|
| // Prepare provider hosts (for the same process).
|
| scoped_ptr<ServiceWorkerProviderHost> host1(new ServiceWorkerProviderHost(
|
| kRenderProcessId, 1 /* provider_id */,
|
| - context_->AsWeakPtr(), NULL));
|
| + context()->AsWeakPtr(), NULL));
|
| scoped_ptr<ServiceWorkerProviderHost> host2(new ServiceWorkerProviderHost(
|
| kRenderProcessId, 2 /* provider_id */,
|
| - context_->AsWeakPtr(), NULL));
|
| + context()->AsWeakPtr(), NULL));
|
| scoped_ptr<ServiceWorkerProviderHost> host3(new ServiceWorkerProviderHost(
|
| kRenderProcessId, 3 /* provider_id */,
|
| - context_->AsWeakPtr(), NULL));
|
| + context()->AsWeakPtr(), NULL));
|
| provider_host1_ = host1->AsWeakPtr();
|
| provider_host2_ = host2->AsWeakPtr();
|
| provider_host3_ = host3->AsWeakPtr();
|
| - context_->AddProviderHost(make_scoped_ptr(host1.release()));
|
| - context_->AddProviderHost(make_scoped_ptr(host2.release()));
|
| - context_->AddProviderHost(make_scoped_ptr(host3.release()));
|
| + provider_registry()->AddProviderHost(make_scoped_ptr(host1.release()));
|
| + provider_registry()->AddProviderHost(make_scoped_ptr(host2.release()));
|
| + provider_registry()->AddProviderHost(make_scoped_ptr(host3.release()));
|
| }
|
|
|
| virtual void TearDown() OVERRIDE {
|
| version_ = 0;
|
| registration_ = 0;
|
| - context_.reset();
|
| + helper_.reset();
|
| + }
|
| +
|
| + ServiceWorkerContextCore* context() {
|
| + return helper_->context();
|
| + }
|
| +
|
| + ServiceWorkerProviderHostRegistry* provider_registry() {
|
| + return helper_->context_wrapper()->provider_registry();
|
| }
|
|
|
| content::TestBrowserThreadBundle thread_bundle_;
|
| - scoped_ptr<ServiceWorkerContextCore> context_;
|
| + scoped_ptr<EmbeddedWorkerTestHelper> helper_;
|
| +
|
| scoped_refptr<ServiceWorkerRegistration> registration_;
|
| scoped_refptr<ServiceWorkerVersion> version_;
|
| base::WeakPtr<ServiceWorkerProviderHost> provider_host1_;
|
| @@ -159,13 +164,7 @@ class ServiceWorkerProviderHostWaitingVersionTest : public testing::Test {
|
| virtual ~ServiceWorkerProviderHostWaitingVersionTest() {}
|
|
|
| virtual void SetUp() OVERRIDE {
|
| - context_.reset(
|
| - new ServiceWorkerContextCore(base::FilePath(),
|
| - base::MessageLoopProxy::current(),
|
| - base::MessageLoopProxy::current(),
|
| - NULL,
|
| - NULL,
|
| - NULL));
|
| + helper_.reset(new EmbeddedWorkerTestHelper(kRenderProcessId));
|
|
|
| // Prepare provider hosts (for the same process).
|
| provider_host1_ = CreateProviderHost(GURL("http://www.example.com/foo"));
|
| @@ -176,19 +175,27 @@ class ServiceWorkerProviderHostWaitingVersionTest : public testing::Test {
|
| base::WeakPtr<ServiceWorkerProviderHost> CreateProviderHost(
|
| const GURL& document_url) {
|
| scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
|
| - kRenderProcessId, next_provider_id_++, context_->AsWeakPtr(), NULL));
|
| + kRenderProcessId, next_provider_id_++, context()->AsWeakPtr(), NULL));
|
| host->SetDocumentUrl(document_url);
|
| base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr();
|
| - context_->AddProviderHost(host.Pass());
|
| + provider_registry()->AddProviderHost(host.Pass());
|
| return provider_host;
|
| }
|
|
|
| virtual void TearDown() OVERRIDE {
|
| - context_.reset();
|
| + helper_.reset();
|
| + }
|
| +
|
| + ServiceWorkerContextCore* context() {
|
| + return helper_->context();
|
| + }
|
| +
|
| + ServiceWorkerProviderHostRegistry* provider_registry() {
|
| + return helper_->context_wrapper()->provider_registry();
|
| }
|
|
|
| content::TestBrowserThreadBundle thread_bundle_;
|
| - scoped_ptr<ServiceWorkerContextCore> context_;
|
| + scoped_ptr<EmbeddedWorkerTestHelper> helper_;
|
| base::WeakPtr<ServiceWorkerProviderHost> provider_host1_;
|
| base::WeakPtr<ServiceWorkerProviderHost> provider_host2_;
|
| base::WeakPtr<ServiceWorkerProviderHost> provider_host3_;
|
| @@ -206,12 +213,12 @@ TEST_F(ServiceWorkerProviderHostWaitingVersionTest,
|
|
|
| scoped_refptr<ServiceWorkerRegistration> registration(
|
| new ServiceWorkerRegistration(
|
| - scope, script_url, 1L, context_->AsWeakPtr()));
|
| + scope, script_url, 1L, context()->AsWeakPtr()));
|
| scoped_refptr<ServiceWorkerVersion> version(
|
| - new ServiceWorkerVersion(registration, 1L, context_->AsWeakPtr()));
|
| + new ServiceWorkerVersion(registration, 1L, context()->AsWeakPtr()));
|
|
|
| ServiceWorkerRegisterJob::AssociateWaitingVersionToDocuments(
|
| - context_->AsWeakPtr(), version.get());
|
| + context()->AsWeakPtr(), version.get());
|
| EXPECT_EQ(version.get(), provider_host1_->waiting_version());
|
| EXPECT_EQ(version.get(), provider_host2_->waiting_version());
|
| EXPECT_EQ(NULL, provider_host3_->waiting_version());
|
| @@ -223,22 +230,22 @@ TEST_F(ServiceWorkerProviderHostWaitingVersionTest,
|
| const GURL script_url1("http://www.example.com/service_worker.js");
|
| scoped_refptr<ServiceWorkerRegistration> registration1(
|
| new ServiceWorkerRegistration(
|
| - scope1, script_url1, 1L, context_->AsWeakPtr()));
|
| + scope1, script_url1, 1L, context()->AsWeakPtr()));
|
| scoped_refptr<ServiceWorkerVersion> version1(
|
| - new ServiceWorkerVersion(registration1, 1L, context_->AsWeakPtr()));
|
| + new ServiceWorkerVersion(registration1, 1L, context()->AsWeakPtr()));
|
|
|
| const GURL scope2("http://www.example.ca/*");
|
| const GURL script_url2("http://www.example.ca/service_worker.js");
|
| scoped_refptr<ServiceWorkerRegistration> registration2(
|
| new ServiceWorkerRegistration(
|
| - scope2, script_url2, 2L, context_->AsWeakPtr()));
|
| + scope2, script_url2, 2L, context()->AsWeakPtr()));
|
| scoped_refptr<ServiceWorkerVersion> version2(
|
| - new ServiceWorkerVersion(registration2, 2L, context_->AsWeakPtr()));
|
| + new ServiceWorkerVersion(registration2, 2L, context()->AsWeakPtr()));
|
|
|
| ServiceWorkerRegisterJob::AssociateWaitingVersionToDocuments(
|
| - context_->AsWeakPtr(), version1.get());
|
| + context()->AsWeakPtr(), version1.get());
|
| ServiceWorkerRegisterJob::AssociateWaitingVersionToDocuments(
|
| - context_->AsWeakPtr(), version2.get());
|
| + context()->AsWeakPtr(), version2.get());
|
|
|
| // Host1 and host2 are associated with version1 as a waiting version, whereas
|
| // host3 is associated with version2.
|
| @@ -248,7 +255,7 @@ TEST_F(ServiceWorkerProviderHostWaitingVersionTest,
|
|
|
| // Disassociate version1 from host1 and host2.
|
| ServiceWorkerRegisterJob::DisassociateWaitingVersionFromDocuments(
|
| - context_->AsWeakPtr(), version1->version_id());
|
| + context()->AsWeakPtr(), version1->version_id());
|
| EXPECT_EQ(NULL, provider_host1_->waiting_version());
|
| EXPECT_EQ(NULL, provider_host2_->waiting_version());
|
| EXPECT_EQ(version2.get(), provider_host3_->waiting_version());
|
|
|