| Index: content/browser/service_worker/service_worker_storage_unittest.cc
|
| diff --git a/content/browser/service_worker/service_worker_storage_unittest.cc b/content/browser/service_worker/service_worker_storage_unittest.cc
|
| index ea615026ad3218db24f673c68f4f439a6c949195..c68ac8860bcf7831bbf3bda4bdcf4bb8d90d9b2c 100644
|
| --- a/content/browser/service_worker/service_worker_storage_unittest.cc
|
| +++ b/content/browser/service_worker/service_worker_storage_unittest.cc
|
| @@ -16,6 +16,7 @@
|
| #include "content/browser/service_worker/service_worker_utils.h"
|
| #include "content/browser/service_worker/service_worker_version.h"
|
| #include "content/common/service_worker/service_worker_status_code.h"
|
| +#include "content/public/test/mock_special_storage_policy.h"
|
| #include "content/public/test/test_browser_thread_bundle.h"
|
| #include "net/base/io_buffer.h"
|
| #include "net/base/net_errors.h"
|
| @@ -192,12 +193,14 @@ class ServiceWorkerStorageTest : public testing::Test {
|
| }
|
|
|
| virtual void SetUp() OVERRIDE {
|
| + special_storage_policy_ = new MockSpecialStoragePolicy();
|
| context_.reset(
|
| new ServiceWorkerContextCore(GetUserDataDirectory(),
|
| base::ThreadTaskRunnerHandle::Get(),
|
| base::ThreadTaskRunnerHandle::Get(),
|
| base::ThreadTaskRunnerHandle::Get(),
|
| NULL,
|
| + special_storage_policy_.get(),
|
| NULL,
|
| NULL));
|
| context_ptr_ = context_->AsWeakPtr();
|
| @@ -320,6 +323,7 @@ class ServiceWorkerStorageTest : public testing::Test {
|
|
|
| scoped_ptr<ServiceWorkerContextCore> context_;
|
| base::WeakPtr<ServiceWorkerContextCore> context_ptr_;
|
| + scoped_refptr<MockSpecialStoragePolicy> special_storage_policy_;
|
| TestBrowserThreadBundle browser_thread_bundle_;
|
| };
|
|
|
| @@ -816,6 +820,7 @@ TEST_F(ServiceWorkerResourceStorageDiskTest, MAYBE_CleanupOnRestart) {
|
| base::ThreadTaskRunnerHandle::Get(),
|
| base::ThreadTaskRunnerHandle::Get(),
|
| NULL,
|
| + special_storage_policy_.get(),
|
| NULL,
|
| NULL));
|
| storage()->LazyInitialize(base::Bind(&base::DoNothing));
|
| @@ -845,6 +850,65 @@ TEST_F(ServiceWorkerResourceStorageDiskTest, MAYBE_CleanupOnRestart) {
|
| EXPECT_TRUE(VerifyBasicResponse(storage(), kNewResourceId, true));
|
| }
|
|
|
| +TEST_F(ServiceWorkerResourceStorageDiskTest, ClearOnExit) {
|
| + // Store a new registration.
|
| + GURL cleared_scope("http://www.test.clear/scope/");
|
| + GURL cleared_script("http://www.test.clear/script.js");
|
| + int64 cleared_registration_id = storage()->NewRegistrationId();
|
| + int64 cleared_version_id = storage()->NewVersionId();
|
| +
|
| + RegistrationData data;
|
| + data.registration_id = cleared_registration_id;
|
| + data.scope = cleared_scope;
|
| + data.script = cleared_script;
|
| + data.version_id = cleared_version_id;
|
| + data.is_active = false;
|
| +
|
| + scoped_refptr<ServiceWorkerRegistration> cleared_registration =
|
| + storage()->GetOrCreateRegistration(data, std::vector<ResourceRecord>());
|
| + cleared_registration->waiting_version()->SetStatus(
|
| + ServiceWorkerVersion::INSTALLED);
|
| + EXPECT_EQ(SERVICE_WORKER_OK,
|
| + StoreRegistration(cleared_registration,
|
| + cleared_registration->waiting_version()));
|
| +
|
| + // Set its origin as session-only.
|
| + special_storage_policy_->AddSessionOnly(cleared_scope.GetOrigin());
|
| +
|
| + // Verify that the registrations are findable.
|
| + scoped_refptr<ServiceWorkerRegistration> found_registration;
|
| + EXPECT_EQ(SERVICE_WORKER_OK,
|
| + FindRegistrationForId(cleared_registration_id,
|
| + cleared_scope.GetOrigin(),
|
| + &found_registration));
|
| + EXPECT_EQ(SERVICE_WORKER_OK,
|
| + FindRegistrationForId(
|
| + registration_id_, scope_.GetOrigin(), &found_registration));
|
| +
|
| + // Simulate browser restart.
|
| + context_.reset();
|
| + context_.reset(
|
| + new ServiceWorkerContextCore(GetUserDataDirectory(),
|
| + base::ThreadTaskRunnerHandle::Get(),
|
| + base::ThreadTaskRunnerHandle::Get(),
|
| + base::ThreadTaskRunnerHandle::Get(),
|
| + NULL,
|
| + special_storage_policy_.get(),
|
| + NULL,
|
| + NULL));
|
| + storage()->LazyInitialize(base::Bind(&base::DoNothing));
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + // Verify that the session-only origin registration is gone.
|
| + EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND,
|
| + FindRegistrationForId(cleared_registration_id,
|
| + cleared_scope.GetOrigin(),
|
| + &found_registration));
|
| + EXPECT_EQ(SERVICE_WORKER_OK,
|
| + FindRegistrationForId(
|
| + registration_id_, scope_.GetOrigin(), &found_registration));
|
| +}
|
| +
|
| TEST_F(ServiceWorkerResourceStorageTest, UpdateRegistration) {
|
| // Promote the worker to active worker and add a controllee.
|
| registration_->SetActiveVersion(registration_->waiting_version());
|
|
|