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

Unified Diff: net/disk_cache/backend_unittest.cc

Issue 17507006: Disk cache v3 ref2 Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Incl IndexTable cl Created 7 years, 1 month 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 | « net/disk_cache/backend_impl.cc ('k') | net/disk_cache/block_files.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/backend_unittest.cc
===================================================================
--- net/disk_cache/backend_unittest.cc (revision 232523)
+++ net/disk_cache/backend_unittest.cc (working copy)
@@ -39,6 +39,7 @@
namespace {
+const int kDelayToNextTimestamp = 60;
const char kExistingEntryKey[] = "existing entry key";
scoped_ptr<disk_cache::BackendImpl> CreateExistingEntryCache(
@@ -91,6 +92,8 @@
void BackendSetSize();
void BackendLoad();
void BackendChain();
+ void BucketUse();
+ void BackendNewEvictionTrim();
void BackendValidEntry();
void BackendInvalidEntry();
void BackendInvalidEntryRead();
@@ -123,6 +126,9 @@
void BackendDisable2();
void BackendDisable3();
void BackendDisable4();
+ void BackendTotalBuffersSize1();
+ void BackendTotalBuffersSize2();
+ void BackendUpdateRankForExternalCacheHit();
void TracingBackendBasics();
};
@@ -342,6 +348,11 @@
BackendBasics();
}
+TEST_F(DiskCacheBackendTest, V3Basics) {
+ UseVersion3();
+ BackendBasics();
+}
+
void DiskCacheBackendTest::BackendKeying() {
InitCache();
const char* kName1 = "the first key";
@@ -387,11 +398,22 @@
BackendKeying();
}
+TEST_F(DiskCacheBackendTest, V3Keying) {
+ UseVersion3();
+ BackendKeying();
+}
+
TEST_F(DiskCacheBackendTest, NewEvictionKeying) {
SetNewEviction();
BackendKeying();
}
+TEST_F(DiskCacheBackendTest, V3NewEvictionKeying) {
+ UseVersion3();
+ SetNewEviction();
+ BackendKeying();
+}
+
TEST_F(DiskCacheBackendTest, MemoryOnlyKeying) {
SetMemoryOnlyMode();
BackendKeying();
@@ -414,7 +436,7 @@
ASSERT_TRUE(CleanupCacheDir());
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
- base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
+ base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
// Test the private factory method(s).
scoped_ptr<disk_cache::Backend> cache;
@@ -423,16 +445,11 @@
cache.reset();
// Now test the public API.
- int rv =
- disk_cache::CreateCacheBackend(net::DISK_CACHE,
- net::CACHE_BACKEND_DEFAULT,
- cache_path_,
- 0,
- false,
- cache_thread.message_loop_proxy().get(),
- NULL,
- &cache,
- cb.callback());
+ int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE,
+ net::CACHE_BACKEND_DEFAULT,
+ cache_path_, 0, false,
+ cache_thread.message_loop_proxy(),
+ NULL, &cache, cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
ASSERT_TRUE(cache.get());
cache.reset();
@@ -457,7 +474,7 @@
base::DeleteFile(filename, false);
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
- base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
+ base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
net::TestCompletionCallback cb;
bool prev = base::ThreadRestrictions::SetIOAllowed(false);
@@ -496,12 +513,12 @@
// Tests that we deal with file-level pending operations at destruction time.
void DiskCacheBackendTest::BackendShutdownWithPendingFileIO(bool fast) {
ASSERT_TRUE(CleanupCacheDir());
- uint32 flags = disk_cache::kNoBuffering;
- if (!fast)
- flags |= disk_cache::kNoRandom;
+ if (fast)
+ AvoidTestFlag();
UseCurrentThread();
- CreateBackend(flags, NULL);
+ CreateBackend(NULL);
+ SetNoBuffering();
net::TestCompletionCallback cb;
int rv = GeneratePendingIO(&cb);
@@ -561,7 +578,8 @@
SetNewEviction(); // Match the expected behavior for integrity verification.
UseCurrentThread();
- CreateBackend(disk_cache::kNoBuffering, NULL);
+ CreateBackend(NULL);
+ SetNoBuffering();
rv = GeneratePendingIO(&cb);
// cache_ has a pending operation, and extra_cache will go away.
@@ -585,13 +603,13 @@
ASSERT_TRUE(CleanupCacheDir());
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
- base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
+ base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
- uint32 flags = disk_cache::kNoBuffering;
- if (!fast)
- flags |= disk_cache::kNoRandom;
+ if (fast)
+ AvoidTestFlag();
- CreateBackend(flags, &cache_thread);
+ CreateBackend(&cache_thread);
+ SetNoBuffering();
disk_cache::Entry* entry;
int rv = cache_->CreateEntry("some key", &entry, cb.callback());
@@ -628,11 +646,11 @@
ASSERT_TRUE(CleanupCacheDir());
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
- base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
+ base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
- disk_cache::BackendFlags flags =
- fast ? disk_cache::kNone : disk_cache::kNoRandom;
- CreateBackend(flags, &cache_thread);
+ if (fast)
+ AvoidTestFlag();
+ CreateBackend(&cache_thread);
disk_cache::Entry* entry;
int rv = cache_->CreateEntry("some key", &entry, cb.callback());
@@ -666,20 +684,13 @@
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
- base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
+ base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
net::TestCompletionCallback cb;
scoped_ptr<disk_cache::Backend> backend;
- int rv =
- disk_cache::CreateCacheBackend(net::DISK_CACHE,
- net::CACHE_BACKEND_BLOCKFILE,
- cache_path_,
- 0,
- false,
- cache_thread.message_loop_proxy().get(),
- NULL,
- &backend,
- cb.callback());
+ int rv = disk_cache::CreateCacheBackend(
+ net::DISK_CACHE, net::CACHE_BACKEND_BLOCKFILE, cache_path_, 0, false,
+ cache_thread.message_loop_proxy(), NULL, &backend, cb.callback());
ASSERT_NE(net::OK, cb.GetResult(rv));
ASSERT_FALSE(backend);
@@ -698,22 +709,22 @@
scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(cache_size));
memset(buffer->data(), 0, cache_size);
EXPECT_EQ(cache_size / 10,
- WriteData(entry, 0, 0, buffer.get(), cache_size / 10, false))
- << "normal file";
+ WriteData(entry, 0, 0, buffer.get(), cache_size / 10, false)) <<
+ "normal file";
EXPECT_EQ(net::ERR_FAILED,
- WriteData(entry, 1, 0, buffer.get(), cache_size / 5, false))
- << "file size above the limit";
+ WriteData(entry, 1, 0, buffer.get(), cache_size / 5, false)) <<
+ "file size above the limit";
// By doubling the total size, we make this file cacheable.
SetMaxSize(cache_size * 2);
- EXPECT_EQ(cache_size / 5,
- WriteData(entry, 1, 0, buffer.get(), cache_size / 5, false));
+ EXPECT_EQ(cache_size / 5, WriteData(entry, 1, 0, buffer.get(), cache_size / 5,
+ false));
// Let's fill up the cache!.
SetMaxSize(cache_size * 10);
- EXPECT_EQ(cache_size * 3 / 4,
- WriteData(entry, 0, 0, buffer.get(), cache_size * 3 / 4, false));
+ EXPECT_EQ(cache_size * 3 / 4, WriteData(entry, 0, 0, buffer.get(),
+ cache_size * 3 / 4, false));
entry->Close();
FlushQueueForTest();
@@ -726,17 +737,20 @@
WriteData(entry, 0, 0, buffer.get(), cache_size / 10, false));
disk_cache::Entry* entry2;
- ASSERT_EQ(net::OK, CreateEntry("an extra key", &entry2));
- EXPECT_EQ(cache_size / 10,
- WriteData(entry2, 0, 0, buffer.get(), cache_size / 10, false));
+ std::string extra_key("an extra key");
+ ASSERT_EQ(net::OK, CreateEntry(extra_key, &entry2));
+ EXPECT_EQ(cache_size / 10, WriteData(entry2, 0, 0, buffer.get(),
+ cache_size / 10, false));
entry2->Close(); // This will trigger the cache trim.
+ WaitForEntryToClose(extra_key);
- EXPECT_NE(net::OK, OpenEntry(first, &entry2));
-
FlushQueueForTest(); // Make sure that we are done trimming the cache.
FlushQueueForTest(); // We may have posted two tasks to evict stuff.
entry->Close();
+ WaitForEntryToClose(second);
+
+ EXPECT_NE(net::OK, OpenEntry(first, &entry2));
ASSERT_EQ(net::OK, OpenEntry(second, &entry));
EXPECT_EQ(cache_size / 10, entry->GetDataSize(0));
entry->Close();
@@ -746,11 +760,24 @@
BackendSetSize();
}
+TEST_F(DiskCacheBackendTest, V3SetSize) {
+ UseVersion3();
+ UseVersion3();
+ SetNewEviction();
+ BackendSetSize();
+}
+
TEST_F(DiskCacheBackendTest, NewEvictionSetSize) {
SetNewEviction();
BackendSetSize();
}
+TEST_F(DiskCacheBackendTest, V3NewEvictionSetSize) {
+ UseVersion3();
+ SetNewEviction();
+ BackendSetSize();
+}
+
TEST_F(DiskCacheBackendTest, MemoryOnlySetSize) {
SetMemoryOnlyMode();
BackendSetSize();
@@ -857,7 +884,101 @@
BackendChain();
}
-TEST_F(DiskCacheBackendTest, NewEvictionTrim) {
+// Tests the proper use of cell buckets while the index grow.
+void DiskCacheBackendTest::BucketUse() {
+ UseVersion3();
+ InitCache();
+ const int kNumEntries = 20;
+ disk_cache::Entry* entries[kNumEntries];
+ std::string key("The first key");
+
+ // This generates kNumEntries collisions so the extra table has to be used.
+ // There are only 2 extra buckets on the test setup, so the index has to grow.
+ for (int i = 0; i < kNumEntries; i++) {
+ ASSERT_EQ(net::OK, CreateEntry(key, &entries[i]));
+ entries[i]->Doom();
+ FlushQueueForTest();
+ }
+
+ for (int i = 0; i < kNumEntries / 2; i++)
+ entries[i]->Close();
+
+ for (int i = 0; i < kNumEntries / 2; i++) {
+ ASSERT_EQ(net::OK, CreateEntry(key, &entries[i]));
+ entries[i]->Doom();
+ }
+
+ for (int i = 0; i < kNumEntries; i++)
+ entries[i]->Close();
+}
+
+TEST_F(DiskCacheBackendTest, V3BucketUse) {
+ BucketUse();
+}
+
+TEST_F(DiskCacheBackendTest, V3DoubleIndexBucketUse) {
+ PresetTestMode(); // Doubles the index instead of a slow growth.
+ BucketUse();
+}
+
+TEST_F(DiskCacheBackendTest, V3DoubleIndex) {
+ UseVersion3();
+ PresetTestMode();
+ InitCache();
+
+ disk_cache::Entry* entry;
+ const int kNumEntries = 200;
+ for (int i = 0; i < kNumEntries; i++) {
+ std::string name(base::StringPrintf("Key %d", i));
+ ASSERT_EQ(net::OK, CreateEntry(name, &entry));
+ entry->Close();
+ FlushQueueForTest();
+ }
+
+ // Generate enough collisions to force growing the extra table (and with it,
+ // the index).
+ const int kNumSavedEntries = 5;
+ disk_cache::Entry* entries[kNumSavedEntries];
+ std::string key("The first key");
+ for (int i = 0; i < kNumSavedEntries; i++) {
+ ASSERT_EQ(net::OK, CreateEntry(key, &entries[i]));
+ entries[i]->Doom();
+ FlushQueueForTest();
+ }
+
+ for (int i = 0; i < kNumSavedEntries; i++)
+ entries[i]->Close();
+
+ // Verify that all entries are there.
+ for (int i = 0; i < kNumEntries; i++) {
+ std::string name(base::StringPrintf("Key %d", i));
+ ASSERT_EQ(net::OK, OpenEntry(name, &entry));
+ entry->Close();
+ }
+}
+
+// This test leaks memory because it simulates a crash.
+TEST_F(DiskCacheBackendTest, DISABLED_V3Backup) {
+ UseVersion3();
+ PresetTestMode();
+ InitCache();
+
+ disk_cache::Entry* entry;
+ std::string name1("First entry");
+ ASSERT_EQ(net::OK, CreateEntry(name1, &entry));
+ entry->Close();
+ WaitForEntryToClose(name1);
+
+ std::string name2("Another entry");
+ ASSERT_EQ(net::OK, CreateEntry(name2, &entry));
+
+ SimulateCrash();
+ EXPECT_EQ(net::OK, OpenEntry(name1, &entry));
+ entry->Close();
+ EXPECT_NE(net::OK, OpenEntry(name2, &entry));
+}
+
+void DiskCacheBackendTest::BackendNewEvictionTrim() {
SetNewEviction();
InitCache();
@@ -866,11 +987,18 @@
std::string name(base::StringPrintf("Key %d", i));
ASSERT_EQ(net::OK, CreateEntry(name, &entry));
entry->Close();
+ AddDelayForTest(kDelayToNextTimestamp);
+
if (i < 90) {
// Entries 0 to 89 are in list 1; 90 to 99 are in list 0.
ASSERT_EQ(net::OK, OpenEntry(name, &entry));
entry->Close();
}
+ if (!(i % 10))
+ FlushQueueForTest();
+
+ if (i == 0 || i == 90)
+ WaitForEntryToClose(name);
}
// The first eviction must come from list 1 (10% limit), the second must come
@@ -887,6 +1015,15 @@
entry->Close();
}
+TEST_F(DiskCacheBackendTest, NewEvictionTrim) {
+ BackendNewEvictionTrim();
+}
+
+TEST_F(DiskCacheBackendTest, V3NewEvictionTrim) {
+ UseVersion3();
+ BackendNewEvictionTrim();
+}
+
// Before looking for invalid entries, let's check a valid entry.
void DiskCacheBackendTest::BackendValidEntry() {
InitCache();
@@ -1217,6 +1354,8 @@
disk_cache::Entry* entry;
ASSERT_EQ(net::OK, CreateEntry(key, &entry));
entry->Close();
+ if (!(i % 10))
+ FlushQueueForTest();
}
EXPECT_EQ(kNumEntries, cache_->GetEntryCount());
Time final = Time::Now();
@@ -1259,11 +1398,22 @@
BackendEnumerations();
}
+TEST_F(DiskCacheBackendTest, V3Enumerations) {
+ UseVersion3();
+ BackendEnumerations();
+}
+
TEST_F(DiskCacheBackendTest, NewEvictionEnumerations) {
SetNewEviction();
BackendEnumerations();
}
+TEST_F(DiskCacheBackendTest, V3NewEvictionEnumerations) {
+ UseVersion3();
+ SetNewEviction();
+ BackendEnumerations();
+}
+
TEST_F(DiskCacheBackendTest, MemoryOnlyEnumerations) {
SetMemoryOnlyMode();
BackendEnumerations();
@@ -1292,7 +1442,7 @@
FlushQueueForTest();
// Make sure that the timestamp is not the same.
- AddDelay();
+ AddDelayForTest(kDelayToNextTimestamp);
ASSERT_EQ(net::OK, OpenEntry(second, &entry1));
void* iter = NULL;
ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2));
@@ -1328,11 +1478,22 @@
BackendEnumerations2();
}
+TEST_F(DiskCacheBackendTest, V3Enumerations2) {
+ UseVersion3();
+ BackendEnumerations2();
+}
+
TEST_F(DiskCacheBackendTest, NewEvictionEnumerations2) {
SetNewEviction();
BackendEnumerations2();
}
+TEST_F(DiskCacheBackendTest, V3NewEvictionEnumerations2) {
+ UseVersion3();
+ SetNewEviction();
+ BackendEnumerations2();
+}
+
TEST_F(DiskCacheBackendTest, MemoryOnlyEnumerations2) {
SetMemoryOnlyMode();
BackendEnumerations2();
@@ -1508,8 +1669,8 @@
entry->Close();
FlushQueueForTest();
- AddDelay();
- Time middle = Time::Now();
+ AddDelayForTest(kDelayToNextTimestamp);
+ Time middle = GetCurrentTime();
ASSERT_EQ(net::OK, CreateEntry("third", &entry));
entry->Close();
@@ -1517,8 +1678,8 @@
entry->Close();
FlushQueueForTest();
- AddDelay();
- Time final = Time::Now();
+ AddDelayForTest(kDelayToNextTimestamp);
+ Time final = GetCurrentTime();
ASSERT_EQ(4, cache_->GetEntryCount());
EXPECT_EQ(net::OK, DoomEntriesSince(final));
@@ -1535,11 +1696,22 @@
BackendDoomRecent();
}
+TEST_F(DiskCacheBackendTest, V3DoomRecent) {
+ UseVersion3();
+ BackendDoomRecent();
+}
+
TEST_F(DiskCacheBackendTest, NewEvictionDoomRecent) {
SetNewEviction();
BackendDoomRecent();
}
+TEST_F(DiskCacheBackendTest, V3NewEvictionDoomRecent) {
+ UseVersion3();
+ SetNewEviction();
+ BackendDoomRecent();
+}
+
TEST_F(DiskCacheBackendTest, MemoryOnlyDoomRecent) {
SetMemoryOnlyMode();
BackendDoomRecent();
@@ -1563,6 +1735,17 @@
EXPECT_EQ(3, cache_->GetEntryCount());
}
+TEST_F(DiskCacheBackendTest, V3DoomEntriesSinceSparse) {
+ base::Time start;
+ UseVersion3();
+ InitSparseCache(&start, NULL);
+ DoomEntriesSince(start);
+ // NOTE: BackendImpl counts child entries in its GetEntryCount(), while
+ // MemBackendImpl does not. Thats why expected value differs here from
+ // MemoryOnlyDoomEntriesSinceSparse.
+ EXPECT_EQ(3, cache_->GetEntryCount());
+}
+
TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAllSparse) {
SetMemoryOnlyMode();
InitSparseCache(NULL, NULL);
@@ -1576,6 +1759,13 @@
EXPECT_EQ(0, cache_->GetEntryCount());
}
+TEST_F(DiskCacheBackendTest, V3DoomAllSparse) {
+ UseVersion3();
+ InitSparseCache(NULL, NULL);
+ EXPECT_EQ(net::OK, DoomAllEntries());
+ EXPECT_EQ(0, cache_->GetEntryCount());
+}
+
void DiskCacheBackendTest::BackendDoomBetween() {
InitCache();
@@ -1624,11 +1814,22 @@
BackendDoomBetween();
}
+TEST_F(DiskCacheBackendTest, V3DoomBetween) {
+ UseVersion3();
+ BackendDoomBetween();
+}
+
TEST_F(DiskCacheBackendTest, NewEvictionDoomBetween) {
SetNewEviction();
BackendDoomBetween();
}
+TEST_F(DiskCacheBackendTest, V3NewEvictionDoomBetween) {
+ UseVersion3();
+ SetNewEviction();
+ BackendDoomBetween();
+}
+
TEST_F(DiskCacheBackendTest, MemoryOnlyDoomBetween) {
SetMemoryOnlyMode();
BackendDoomBetween();
@@ -1659,6 +1860,19 @@
EXPECT_EQ(3, cache_->GetEntryCount());
}
+TEST_F(DiskCacheBackendTest, V3DoomEntriesBetweenSparse) {
+ base::Time start, end;
+ UseVersion3();
+ InitSparseCache(&start, &end);
+ DoomEntriesBetween(start, end);
+ EXPECT_EQ(9, cache_->GetEntryCount());
+
+ start = end;
+ end = base::Time::Now();
+ DoomEntriesBetween(start, end);
+ EXPECT_EQ(3, cache_->GetEntryCount());
+}
+
void DiskCacheBackendTest::BackendTransaction(const std::string& name,
int num_entries, bool load) {
success_ = false;
@@ -1807,7 +2021,7 @@
ASSERT_TRUE(CopyTestCache("wrong_version"));
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
- base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
+ base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
net::TestCompletionCallback cb;
scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl(
@@ -1941,21 +2155,16 @@
SetNewEviction();
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
- base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
+ base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
net::TestCompletionCallback cb;
bool prev = base::ThreadRestrictions::SetIOAllowed(false);
base::FilePath path(cache_path_);
- int rv =
- disk_cache::CreateCacheBackend(net::DISK_CACHE,
- net::CACHE_BACKEND_BLOCKFILE,
- path,
- 0,
- true,
- cache_thread.message_loop_proxy().get(),
- NULL,
- &cache_,
- cb.callback());
+ int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE,
+ net::CACHE_BACKEND_BLOCKFILE, path,
+ 0, true,
+ cache_thread.message_loop_proxy(),
+ NULL, &cache_, cb.callback());
path.clear(); // Make sure path was captured by the previous call.
ASSERT_EQ(net::OK, cb.GetResult(rv));
base::ThreadRestrictions::SetIOAllowed(prev);
@@ -2711,7 +2920,8 @@
ASSERT_TRUE(CleanupCacheDir());
scoped_ptr<disk_cache::BackendImpl> cache;
cache.reset(new disk_cache::BackendImpl(
- cache_path_, base::MessageLoopProxy::current().get(), NULL));
+ cache_path_, base::MessageLoopProxy::current(),
+ NULL));
ASSERT_TRUE(NULL != cache.get());
cache->SetUnitTestMode();
ASSERT_EQ(net::OK, cache->SyncInit());
@@ -2799,11 +3009,22 @@
BackendDoomAll();
}
+TEST_F(DiskCacheBackendTest, V3DoomAll) {
+ UseVersion3();
+ BackendDoomAll();
+}
+
TEST_F(DiskCacheBackendTest, NewEvictionDoomAll) {
SetNewEviction();
BackendDoomAll();
}
+TEST_F(DiskCacheBackendTest, V3NewEvictionDoomAll) {
+ UseVersion3();
+ SetNewEviction();
+ BackendDoomAll();
+}
+
TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) {
SetMemoryOnlyMode();
BackendDoomAll();
@@ -2863,26 +3084,13 @@
const int kNumberOfCaches = 2;
scoped_ptr<disk_cache::Backend> cache[kNumberOfCaches];
- int rv =
- disk_cache::CreateCacheBackend(net::DISK_CACHE,
- net::CACHE_BACKEND_DEFAULT,
- store1.path(),
- 0,
- false,
- cache_thread.message_loop_proxy().get(),
- NULL,
- &cache[0],
- cb.callback());
+ int rv = disk_cache::CreateCacheBackend(
+ net::DISK_CACHE, net::CACHE_BACKEND_DEFAULT, store1.path(), 0, false,
+ cache_thread.message_loop_proxy(), NULL, &cache[0], cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
- rv = disk_cache::CreateCacheBackend(net::MEDIA_CACHE,
- net::CACHE_BACKEND_DEFAULT,
- store2.path(),
- 0,
- false,
- cache_thread.message_loop_proxy().get(),
- NULL,
- &cache[1],
- cb.callback());
+ rv = disk_cache::CreateCacheBackend(
+ net::MEDIA_CACHE, net::CACHE_BACKEND_DEFAULT, store2.path(), 0, false,
+ cache_thread.message_loop_proxy(), NULL, &cache[1], cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
ASSERT_TRUE(cache[0].get() != NULL && cache[1].get() != NULL);
@@ -2958,7 +3166,7 @@
// Make sure that we keep the total memory used by the internal buffers under
// control.
-TEST_F(DiskCacheBackendTest, TotalBuffersSize1) {
+void DiskCacheBackendTest::BackendTotalBuffersSize1() {
InitCache();
std::string key("the first key");
disk_cache::Entry* entry;
@@ -2988,35 +3196,53 @@
}
entry->Close();
- EXPECT_EQ(0, cache_impl_->GetTotalBuffersSize());
+ EXPECT_EQ(0, GetTotalBuffersSize());
}
+TEST_F(DiskCacheBackendTest, TotalBuffersSize1) {
+ BackendTotalBuffersSize1();
+}
+
+TEST_F(DiskCacheBackendTest, V3TotalBuffersSize1) {
+ UseVersion3();
+ BackendTotalBuffersSize1();
+}
+
// This test assumes at least 150MB of system memory.
-TEST_F(DiskCacheBackendTest, TotalBuffersSize2) {
+void DiskCacheBackendTest::BackendTotalBuffersSize2() {
InitCache();
const int kOneMB = 1024 * 1024;
- EXPECT_TRUE(cache_impl_->IsAllocAllowed(0, kOneMB));
- EXPECT_EQ(kOneMB, cache_impl_->GetTotalBuffersSize());
+ EXPECT_TRUE(IsAllocAllowed(0, kOneMB));
+ EXPECT_EQ(kOneMB, GetTotalBuffersSize());
- EXPECT_TRUE(cache_impl_->IsAllocAllowed(0, kOneMB));
- EXPECT_EQ(kOneMB * 2, cache_impl_->GetTotalBuffersSize());
+ EXPECT_TRUE(IsAllocAllowed(0, kOneMB));
+ EXPECT_EQ(kOneMB * 2, GetTotalBuffersSize());
- EXPECT_TRUE(cache_impl_->IsAllocAllowed(0, kOneMB));
- EXPECT_EQ(kOneMB * 3, cache_impl_->GetTotalBuffersSize());
+ EXPECT_TRUE(IsAllocAllowed(0, kOneMB));
+ EXPECT_EQ(kOneMB * 3, GetTotalBuffersSize());
- cache_impl_->BufferDeleted(kOneMB);
- EXPECT_EQ(kOneMB * 2, cache_impl_->GetTotalBuffersSize());
+ BufferDeleted(kOneMB);
+ EXPECT_EQ(kOneMB * 2, GetTotalBuffersSize());
// Check the upper limit.
- EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, 30 * kOneMB));
+ EXPECT_FALSE(IsAllocAllowed(0, 30 * kOneMB));
for (int i = 0; i < 30; i++)
- cache_impl_->IsAllocAllowed(0, kOneMB); // Ignore the result.
+ IsAllocAllowed(0, kOneMB); // Ignore the result.
- EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, kOneMB));
+ EXPECT_FALSE(IsAllocAllowed(0, kOneMB));
}
+TEST_F(DiskCacheBackendTest, TotalBuffersSize2) {
+ BackendTotalBuffersSize2();
+}
+
+TEST_F(DiskCacheBackendTest, V3TotalBuffersSize2) {
+ UseVersion3();
+ BackendTotalBuffersSize2();
+}
+
// Tests that sharing of external files works and we are able to delete the
// files when we need to.
TEST_F(DiskCacheBackendTest, FileSharing) {
@@ -3057,7 +3283,7 @@
EXPECT_TRUE(disk_cache::DeleteCacheFile(name));
}
-TEST_F(DiskCacheBackendTest, UpdateRankForExternalCacheHit) {
+void DiskCacheBackendTest::BackendUpdateRankForExternalCacheHit() {
InitCache();
disk_cache::Entry* entry;
@@ -3066,40 +3292,41 @@
std::string key = base::StringPrintf("key%d", i);
ASSERT_EQ(net::OK, CreateEntry(key, &entry));
entry->Close();
+ AddDelayForTest(kDelayToNextTimestamp);
}
+ FlushQueueForTest();
// Ping the oldest entry.
+ SetTestMode();
cache_->OnExternalCacheHit("key0");
+ FlushQueueForTest();
TrimForTest(false);
// Make sure the older key remains.
- EXPECT_EQ(1, cache_->GetEntryCount());
+ EXPECT_NE(net::OK, OpenEntry("key1", &entry));
ASSERT_EQ(net::OK, OpenEntry("key0", &entry));
entry->Close();
}
+TEST_F(DiskCacheBackendTest, UpdateRankForExternalCacheHit) {
+ BackendUpdateRankForExternalCacheHit();
+}
+
+TEST_F(DiskCacheBackendTest, V3UpdateRankForExternalCacheHit) {
+ UseVersion3();
+ BackendUpdateRankForExternalCacheHit();
+}
+
TEST_F(DiskCacheBackendTest, ShaderCacheUpdateRankForExternalCacheHit) {
SetCacheType(net::SHADER_CACHE);
- InitCache();
+ BackendUpdateRankForExternalCacheHit();
+}
- disk_cache::Entry* entry;
-
- for (int i = 0; i < 2; ++i) {
- std::string key = base::StringPrintf("key%d", i);
- ASSERT_EQ(net::OK, CreateEntry(key, &entry));
- entry->Close();
- }
-
- // Ping the oldest entry.
- cache_->OnExternalCacheHit("key0");
-
- TrimForTest(false);
-
- // Make sure the older key remains.
- EXPECT_EQ(1, cache_->GetEntryCount());
- ASSERT_EQ(net::OK, OpenEntry("key0", &entry));
- entry->Close();
+TEST_F(DiskCacheBackendTest, V3ShaderCacheUpdateRankForExternalCacheHit) {
+ UseVersion3();
+ SetCacheType(net::SHADER_CACHE);
+ BackendUpdateRankForExternalCacheHit();
}
void DiskCacheBackendTest::TracingBackendBasics() {
« no previous file with comments | « net/disk_cache/backend_impl.cc ('k') | net/disk_cache/block_files.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698