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

Unified Diff: content/browser/cache_storage/cache_storage_manager_unittest.cc

Issue 2232223003: [CacheStorage] Check doomed caches first when dropping cache handles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Rebase Created 4 years, 4 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
Index: content/browser/cache_storage/cache_storage_manager_unittest.cc
diff --git a/content/browser/cache_storage/cache_storage_manager_unittest.cc b/content/browser/cache_storage/cache_storage_manager_unittest.cc
index 0da84acf861ccc1bd09eaf6adfee05c93ff9a60d..8fa9c391c70def9860367b92dc113e2a1fde5f66 100644
--- a/content/browser/cache_storage/cache_storage_manager_unittest.cc
+++ b/content/browser/cache_storage/cache_storage_manager_unittest.cc
@@ -450,7 +450,12 @@ TEST_P(CacheStorageManagerTestP, DeleteCacheReducesOriginSize) {
int64_t put_delta = quota_manager_proxy_->last_notified_delta();
EXPECT_LT(0, put_delta);
EXPECT_TRUE(Delete(origin1_, "foo"));
- EXPECT_EQ(put_delta, -1 * quota_manager_proxy_->last_notified_delta());
+
+ // Drop the cache handle so that the cache can be erased from disk.
+ callback_cache_handle_ = nullptr;
+ base::RunLoop().RunUntilIdle();
+
+ EXPECT_EQ(-1 * quota_manager_proxy_->last_notified_delta(), put_delta);
}
TEST_P(CacheStorageManagerTestP, EmptyKeys) {
@@ -543,6 +548,31 @@ TEST_F(CacheStorageManagerTest, StorageReuseCacheName) {
EXPECT_TRUE(CachePut(callback_cache_handle_->value(), kTestURL));
}
+TEST_P(CacheStorageManagerTestP, DropRefAfterNewCacheWithSameNameCreated) {
+ // Make sure that dropping the final cache handle to a doomed cache doesn't
+ // affect newer caches with the same name. (see crbug.com/631467)
+
+ // 1. Create cache A and hang onto the handle
+ const GURL kTestURL = GURL("http://example.com/foo");
+ EXPECT_TRUE(Open(origin1_, "foo"));
+ EXPECT_FALSE(CacheMatch(callback_cache_handle_->value(), kTestURL));
+ std::unique_ptr<CacheStorageCacheHandle> cache_handle =
+ std::move(callback_cache_handle_);
+
+ // 2. Doom the cache
+ EXPECT_TRUE(Delete(origin1_, "foo"));
+
+ // 3. Create cache B (with the same name)
+ EXPECT_TRUE(Open(origin1_, "foo"));
+ EXPECT_FALSE(CacheMatch(callback_cache_handle_->value(), kTestURL));
+
+ // 4. Drop handle to A
+ cache_handle.reset();
+
+ // 5. Verify that B still works
+ EXPECT_FALSE(CacheMatch(callback_cache_handle_->value(), kTestURL));
+}
+
TEST_P(CacheStorageManagerTestP, StorageMatchAllEntryExistsTwice) {
EXPECT_TRUE(Open(origin1_, "foo"));
EXPECT_TRUE(CachePutWithStatusCode(callback_cache_handle_->value(),
@@ -649,6 +679,43 @@ TEST_F(CacheStorageManagerTest, DropReference) {
EXPECT_FALSE(cache);
}
+// A cache continues to work so long as there is a handle to it. Only after the
+// last cache handle is deleted can the cache be freed.
+TEST_P(CacheStorageManagerTestP, CacheWorksAfterDelete) {
+ const GURL kFooURL("http://example.com/foo");
+ const GURL kBarURL("http://example.com/bar");
+ const GURL kBazURL("http://example.com/baz");
+ EXPECT_TRUE(Open(origin1_, "foo"));
+ std::unique_ptr<CacheStorageCacheHandle> original_handle =
+ std::move(callback_cache_handle_);
+ EXPECT_TRUE(CachePut(original_handle->value(), kFooURL));
+ EXPECT_TRUE(Delete(origin1_, "foo"));
+
+ // Verify that the existing cache handle still works.
+ EXPECT_TRUE(CacheMatch(original_handle->value(), kFooURL));
+ EXPECT_TRUE(CachePut(original_handle->value(), kBarURL));
+ EXPECT_TRUE(CacheMatch(original_handle->value(), kBarURL));
+
+ // The cache shouldn't be visible to subsequent storage operations.
+ EXPECT_TRUE(Keys(origin1_));
+ EXPECT_TRUE(callback_strings_.empty());
+
+ // Open a new cache with the same name, it should create a new cache, but not
+ // interfere with the original cache.
+ EXPECT_TRUE(Open(origin1_, "foo"));
+ std::unique_ptr<CacheStorageCacheHandle> new_handle =
+ std::move(callback_cache_handle_);
+ EXPECT_TRUE(CachePut(new_handle->value(), kBazURL));
+
+ EXPECT_FALSE(CacheMatch(new_handle->value(), kFooURL));
+ EXPECT_FALSE(CacheMatch(new_handle->value(), kBarURL));
+ EXPECT_TRUE(CacheMatch(new_handle->value(), kBazURL));
+
+ EXPECT_TRUE(CacheMatch(original_handle->value(), kFooURL));
+ EXPECT_TRUE(CacheMatch(original_handle->value(), kBarURL));
+ EXPECT_FALSE(CacheMatch(original_handle->value(), kBazURL));
+}
+
// With a memory cache the cache can't be freed from memory until the client
// calls delete.
TEST_F(CacheStorageManagerMemoryOnlyTest, MemoryLosesReferenceOnlyAfterDelete) {
@@ -658,6 +725,7 @@ TEST_F(CacheStorageManagerMemoryOnlyTest, MemoryLosesReferenceOnlyAfterDelete) {
callback_cache_handle_ = nullptr;
EXPECT_TRUE(cache);
EXPECT_TRUE(Delete(origin1_, "foo"));
+ base::RunLoop().RunUntilIdle();
EXPECT_FALSE(cache);
}

Powered by Google App Engine
This is Rietveld 408576698