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

Unified Diff: net/disk_cache/backend_unittest.cc

Issue 1715833002: Reland: Refactor and shorten in-memory cache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typo in comment Created 4 years, 10 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 | « no previous file | net/disk_cache/entry_unittest.cc » ('j') | net/disk_cache/memory/mem_entry_impl.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/backend_unittest.cc
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index f82699545bcb7e9cdcdcc807920dbf0e95858141..ebd2f578ae578a2df3d50d7b20f2642d0d26aa4d 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -7,6 +7,7 @@
#include "base/files/file_util.h"
#include "base/metrics/field_trial.h"
#include "base/run_loop.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
@@ -136,6 +137,8 @@ class DiskCacheBackendTest : public DiskCacheTestWithCache {
void BackendDisable3();
void BackendDisable4();
void BackendDisabledAPI();
+
+ void BackendEviction();
};
int DiskCacheBackendTest::GeneratePendingIO(net::TestCompletionCallback* cb) {
@@ -2901,6 +2904,49 @@ TEST_F(DiskCacheBackendTest, NewEvictionDisabledAPI) {
BackendDisabledAPI();
}
+// Test that some eviction of some kind happens.
+void DiskCacheBackendTest::BackendEviction() {
+ const int kMaxSize = 200 * 1024;
+ const int kMaxEntryCount = 20;
+ const int kWriteSize = kMaxSize / kMaxEntryCount;
+
+ const int kWriteEntryCount = kMaxEntryCount * 2;
+
+ static_assert(kWriteEntryCount * kWriteSize > kMaxSize,
+ "must write more than MaxSize");
+
+ SetMaxSize(kMaxSize);
+ InitSparseCache(nullptr, nullptr);
+
+ scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kWriteSize));
+ CacheTestFillBuffer(buffer->data(), kWriteSize, false);
+
+ std::string key_prefix("prefix");
+ for (int i = 0; i < kWriteEntryCount; ++i) {
+ AddDelay();
+ disk_cache::Entry* entry = NULL;
+ ASSERT_EQ(net::OK, CreateEntry(key_prefix + base::IntToString(i), &entry));
+ disk_cache::ScopedEntryPtr entry_closer(entry);
+ EXPECT_EQ(kWriteSize,
+ WriteData(entry, 1, 0, buffer.get(), kWriteSize, false));
+ }
+
+ int size = CalculateSizeOfAllEntries();
+ EXPECT_GT(kMaxSize, size);
+}
+
+TEST_F(DiskCacheBackendTest, BackendEviction) {
+ BackendEviction();
+}
+
+TEST_F(DiskCacheBackendTest, MemoryOnlyBackendEviction) {
+ SetMemoryOnlyMode();
+ BackendEviction();
+}
+
+// TODO(gavinp): Enable BackendEviction test for simple cache after performance
+// problems are addressed. See crbug.com/588184 for more information.
+
TEST_F(DiskCacheTest, Backend_UsageStatsTimer) {
MessageLoopHelper helper;
« no previous file with comments | « no previous file | net/disk_cache/entry_unittest.cc » ('j') | net/disk_cache/memory/mem_entry_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698