Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1429)

Unified Diff: content/browser/service_worker/service_worker_storage_unittest.cc

Issue 374873002: Service Worker: Delay stale resource cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch for landing Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/service_worker/service_worker_storage.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 93fee33bda2359bca799b05ccdf67a86a35c9b17..2d7e7eec6d567b70baae02f6f780423218b12153 100644
--- a/content/browser/service_worker/service_worker_storage_unittest.cc
+++ b/content/browser/service_worker/service_worker_storage_unittest.cc
@@ -524,11 +524,13 @@ class ServiceWorkerResourceStorageTest : public ServiceWorkerStorageTest {
registration_->waiting_version()->SetStatus(ServiceWorkerVersion::NEW);
// Add the resources ids to the uncommitted list.
- std::set<int64> resource_ids;
- resource_ids.insert(resource_id1_);
- resource_ids.insert(resource_id2_);
+ storage()->StoreUncommittedResponseId(resource_id1_);
+ storage()->StoreUncommittedResponseId(resource_id2_);
+ base::RunLoop().RunUntilIdle();
+ std::set<int64> verify_ids;
EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
- storage()->database_->WriteUncommittedResourceIds(resource_ids));
+ storage()->database_->GetUncommittedResourceIds(&verify_ids));
+ EXPECT_EQ(2u, verify_ids.size());
// And dump something in the disk cache for them.
WriteBasicResponse(storage(), resource_id1_);
@@ -541,7 +543,7 @@ class ServiceWorkerResourceStorageTest : public ServiceWorkerStorageTest {
EXPECT_EQ(
SERVICE_WORKER_OK,
StoreRegistration(registration_, registration_->waiting_version()));
- std::set<int64> verify_ids;
+ verify_ids.clear();
EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
storage()->database_->GetUncommittedResourceIds(&verify_ids));
EXPECT_TRUE(verify_ids.empty());
@@ -699,7 +701,20 @@ TEST_F(ServiceWorkerResourceStorageDiskTest, MAYBE_CleanupOnRestart) {
EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true));
EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id2_, true));
- // Simulate browser restart. This should trigger stale resource purging.
+ // Also add an uncommitted resource.
+ int64 kStaleUncommittedResourceId = storage()->NewResourceId();
+ storage()->StoreUncommittedResponseId(kStaleUncommittedResourceId);
+ base::RunLoop().RunUntilIdle();
+ verify_ids.clear();
+ EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
+ storage()->database_->GetUncommittedResourceIds(&verify_ids));
+ EXPECT_EQ(1u, verify_ids.size());
+ WriteBasicResponse(storage(), kStaleUncommittedResourceId);
+ EXPECT_TRUE(
+ VerifyBasicResponse(storage(), kStaleUncommittedResourceId, true));
+
+ // Simulate browser shutdown. The purgeable and uncommitted resources are now
+ // stale.
context_.reset();
context_.reset(new ServiceWorkerContextCore(GetUserDataDirectory(),
base::MessageLoopProxy::current(),
@@ -707,18 +722,31 @@ TEST_F(ServiceWorkerResourceStorageDiskTest, MAYBE_CleanupOnRestart) {
NULL,
NULL,
NULL));
- // Use FindRegistration to force storage system initialization.
- scoped_refptr<ServiceWorkerRegistration> found_registration;
- FindRegistrationForDocument(document_url_, &found_registration);
+ storage()->LazyInitialize(base::Bind(&base::DoNothing));
+ base::RunLoop().RunUntilIdle();
+
+ // Store a new uncommitted resource. This triggers stale resource cleanup.
+ int64 kNewResourceId = storage()->NewResourceId();
+ WriteBasicResponse(storage(), kNewResourceId);
+ storage()->StoreUncommittedResponseId(kNewResourceId);
base::RunLoop().RunUntilIdle();
- // Stale resources should be gone.
+ // The stale resources should be purged, but the new resource should persist.
+ verify_ids.clear();
+ EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
+ storage()->database_->GetUncommittedResourceIds(&verify_ids));
+ ASSERT_EQ(1u, verify_ids.size());
+ EXPECT_EQ(kNewResourceId, *verify_ids.begin());
+
verify_ids.clear();
EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
storage()->database_->GetPurgeableResourceIds(&verify_ids));
EXPECT_TRUE(verify_ids.empty());
EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false));
EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false));
+ EXPECT_FALSE(
+ VerifyBasicResponse(storage(), kStaleUncommittedResourceId, false));
+ EXPECT_TRUE(VerifyBasicResponse(storage(), kNewResourceId, true));
}
TEST_F(ServiceWorkerResourceStorageTest, UpdateRegistration) {
« no previous file with comments | « content/browser/service_worker/service_worker_storage.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698