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

Unified Diff: content/browser/dom_storage/dom_storage_context_impl_unittest.cc

Issue 1953703004: Purge browser cache for dom storage in a smarter way (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dom_storage
Patch Set: Fix limit and description for UMA. Created 4 years, 7 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/dom_storage/dom_storage_context_impl_unittest.cc
diff --git a/content/browser/dom_storage/dom_storage_context_impl_unittest.cc b/content/browser/dom_storage/dom_storage_context_impl_unittest.cc
index cd13ccbda454f32baea9d39b7735d122a7f75481..47548530bb8990e738cf3d103feb7f87ff0e2bf9 100644
--- a/content/browser/dom_storage/dom_storage_context_impl_unittest.cc
+++ b/content/browser/dom_storage/dom_storage_context_impl_unittest.cc
@@ -268,4 +268,35 @@ TEST_F(DOMStorageContextImplTest, DeleteSessionStorage) {
base::MessageLoop::current()->RunUntilIdle();
}
+TEST_F(DOMStorageContextImplTest, PurgeMemory) {
+ auto dom_namespace = context_->GetStorageNamespace(kLocalStorageNamespaceId);
+ auto area1 = dom_namespace->OpenStorageArea(kOrigin);
+ area1->InitialImportIfNeeded();
+
+ // PURGE_UNOPENED does not delete the open area.
+ context_->PurgeMemory(DOMStorageContextImpl::PURGE_UNOPENED);
+ EXPECT_EQ(1u, dom_namespace->GetUsageStatistics().total_area_count);
+ EXPECT_EQ(0u, dom_namespace->GetUsageStatistics().inactive_area_count);
+
+ // PURGE_UNOPENED deletes the unopened area.
+ dom_namespace->CloseStorageArea(area1);
+ EXPECT_EQ(1u, dom_namespace->GetUsageStatistics().inactive_area_count);
+ context_->PurgeMemory(DOMStorageContextImpl::PURGE_UNOPENED);
+ EXPECT_EQ(0u, dom_namespace->GetUsageStatistics().total_area_count);
+
+ // Add an item to the database and commit changes, and keep it open. So, cache
+ // is kept alive.
+ auto area2 = dom_namespace->OpenStorageArea(kOrigin);
+ base::NullableString16 old_value;
+ area2->SetItem(kKey, kValue, &old_value);
+ // Call commit directly instead of posting task.
+ area2->CommitChanges(area2->commit_batch_.get());
+ area2->commit_batch_ = nullptr;
+
+ // PURGE_AGGRESSIVE clears the cache in the open area.
+ EXPECT_NE(0u, dom_namespace->GetUsageStatistics().total_cache_size);
+ context_->PurgeMemory(DOMStorageContextImpl::PURGE_AGGRESSIVE);
+ EXPECT_EQ(0u, dom_namespace->GetUsageStatistics().total_cache_size);
+}
+
} // namespace content
« no previous file with comments | « content/browser/dom_storage/dom_storage_context_impl.cc ('k') | content/browser/dom_storage/dom_storage_context_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698