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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/files/file_util.h" 6 #include "base/files/file_util.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 dom_namespace = context_->GetStorageNamespace(kSessionStorageNamespaceId); 261 dom_namespace = context_->GetStorageNamespace(kSessionStorageNamespaceId);
262 area = dom_namespace->OpenStorageArea(kOrigin); 262 area = dom_namespace->OpenStorageArea(kOrigin);
263 read_value = area->GetItem(kKey); 263 read_value = area->GetItem(kKey);
264 EXPECT_TRUE(read_value.is_null()); 264 EXPECT_TRUE(read_value.is_null());
265 dom_namespace->CloseStorageArea(area); 265 dom_namespace->CloseStorageArea(area);
266 context_->Shutdown(); 266 context_->Shutdown();
267 context_ = NULL; 267 context_ = NULL;
268 base::MessageLoop::current()->RunUntilIdle(); 268 base::MessageLoop::current()->RunUntilIdle();
269 } 269 }
270 270
271 TEST_F(DOMStorageContextImplTest, PurgeMemory) {
272 auto dom_namespace = context_->GetStorageNamespace(kLocalStorageNamespaceId);
273 auto area1 = dom_namespace->OpenStorageArea(kOrigin);
274 area1->InitialImportIfNeeded();
275
276 // PURGE_UNOPENED does not delete the open area.
277 context_->PurgeMemory(DOMStorageContextImpl::PURGE_UNOPENED);
278 EXPECT_EQ(1u, dom_namespace->GetUsageStatistics().total_area_count);
279 EXPECT_EQ(0u, dom_namespace->GetUsageStatistics().inactive_area_count);
280
281 // PURGE_UNOPENED deletes the unopened area.
282 dom_namespace->CloseStorageArea(area1);
283 EXPECT_EQ(1u, dom_namespace->GetUsageStatistics().inactive_area_count);
284 context_->PurgeMemory(DOMStorageContextImpl::PURGE_UNOPENED);
285 EXPECT_EQ(0u, dom_namespace->GetUsageStatistics().total_area_count);
286
287 // Add an item to the database and commit changes, and keep it open. So, cache
288 // is kept alive.
289 auto area2 = dom_namespace->OpenStorageArea(kOrigin);
290 base::NullableString16 old_value;
291 area2->SetItem(kKey, kValue, &old_value);
292 // Call commit directly instead of posting task.
293 area2->CommitChanges(area2->commit_batch_.get());
294 area2->commit_batch_ = nullptr;
295
296 // PURGE_AGGRESSIVE clears the cache in the open area.
297 EXPECT_NE(0u, dom_namespace->GetUsageStatistics().total_cache_size);
298 context_->PurgeMemory(DOMStorageContextImpl::PURGE_AGGRESSIVE);
299 EXPECT_EQ(0u, dom_namespace->GetUsageStatistics().total_cache_size);
300 }
301
271 } // namespace content 302 } // namespace content
OLDNEW
« 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