Chromium Code Reviews| 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..83fab0e2669d96802f570dfdf0b2485d7a274889 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,55 @@ 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::NEW); |
|
michaeln1
2014/10/08 19:28:57
to more closely mimic actual usage, i think the wa
|
| + 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()); |
| + |
| + // 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 only the session-only origin is gone. |
| + scoped_refptr<ServiceWorkerRegistration> found_registration; |
| + EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, |
| + FindRegistrationForId(cleared_registration_id, |
|
michaeln1
2014/10/08 19:28:57
maybe test that it actually can be found prior to
|
| + 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()); |