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

Unified Diff: net/disk_cache/backend_unittest.cc

Issue 12794003: Initialize the simple cache backend at runtime. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 9 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: net/disk_cache/backend_unittest.cc
===================================================================
--- net/disk_cache/backend_unittest.cc (revision 188696)
+++ net/disk_cache/backend_unittest.cc (working copy)
@@ -217,24 +217,18 @@
ASSERT_TRUE(cache_thread.StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0)));
- // Test the private factory methods.
+ // Test the private factory method(s).
disk_cache::Backend* cache = NULL;
- int rv = disk_cache::BackendImpl::CreateBackend(
- cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
- cache_thread.message_loop_proxy(), NULL, &cache, cb.callback());
- ASSERT_EQ(net::OK, cb.GetResult(rv));
- ASSERT_TRUE(cache);
- delete cache;
-
cache = disk_cache::MemBackendImpl::CreateBackend(0, NULL);
ASSERT_TRUE(cache);
delete cache;
cache = NULL;
// Now test the public API.
- rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, cache_path_, 0, false,
- cache_thread.message_loop_proxy(),
- NULL, &cache, cb.callback());
+ int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, cache_path_, 0,
+ false,
+ cache_thread.message_loop_proxy(),
+ NULL, &cache, cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
ASSERT_TRUE(cache);
delete cache;
@@ -260,7 +254,7 @@
SetForceCreation();
bool prev = base::ThreadRestrictions::SetIOAllowed(false);
- InitCache();
+ InitDefaultCacheViaCreator();
base::ThreadRestrictions::SetIOAllowed(prev);
}
@@ -301,12 +295,9 @@
uint32 flags = disk_cache::kNoBuffering;
if (!fast)
flags |= disk_cache::kNoRandom;
- rv = disk_cache::BackendImpl::CreateBackend(
- cache_path_, false, 0, net::DISK_CACHE, flags,
- base::MessageLoopProxy::current(), NULL,
- &cache, cb.callback());
- ASSERT_EQ(net::OK, cb.GetResult(rv));
+ cache = CreateBackendAsModeSuggests(flags, NULL);
+
disk_cache::EntryImpl* entry;
rv = cache->CreateEntry(
"some key", reinterpret_cast<disk_cache::Entry**>(&entry),
@@ -373,19 +364,17 @@
ASSERT_TRUE(CleanupCacheDir());
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
- base::Thread::Options(MessageLoop::TYPE_IO, 0)));
+ base::Thread::Options(MessageLoop::TYPE_IO, 0)));
disk_cache::Backend* cache;
uint32 flags = disk_cache::kNoBuffering;
if (!fast)
flags |= disk_cache::kNoRandom;
- int rv = disk_cache::BackendImpl::CreateBackend(
- cache_path_, false, 0, net::DISK_CACHE, flags,
- cache_thread.message_loop_proxy(), NULL, &cache, cb.callback());
- ASSERT_EQ(net::OK, cb.GetResult(rv));
+ cache = CreateBackendAsModeSuggests(flags, &cache_thread);
+
disk_cache::Entry* entry;
- rv = cache->CreateEntry("some key", &entry, cb.callback());
+ int rv = cache->CreateEntry("some key", &entry, cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
entry->Close();
@@ -422,13 +411,10 @@
disk_cache::Backend* cache;
disk_cache::BackendFlags flags =
fast ? disk_cache::kNone : disk_cache::kNoRandom;
- int rv = disk_cache::BackendImpl::CreateBackend(
- cache_path_, false, 0, net::DISK_CACHE, flags,
- cache_thread.message_loop_proxy(), NULL, &cache, cb.callback());
- ASSERT_EQ(net::OK, cb.GetResult(rv));
+ cache = CreateBackendAsModeSuggests(flags, &cache_thread);
disk_cache::Entry* entry;
- rv = cache->CreateEntry("some key", &entry, cb.callback());
+ int rv = cache->CreateEntry("some key", &entry, cb.callback());
ASSERT_EQ(net::ERR_IO_PENDING, rv);
delete cache;
@@ -461,8 +447,8 @@
net::TestCompletionCallback cb;
disk_cache::Backend* backend = NULL;
- int rv = disk_cache::BackendImpl::CreateBackend(
- cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNone,
+ int rv = disk_cache::CreateCacheBackend(
+ net::DISK_CACHE, cache_path_, 0, false,
cache_thread.message_loop_proxy(), NULL, &backend, cb.callback());
ASSERT_NE(net::OK, cb.GetResult(rv));
@@ -471,7 +457,6 @@
}
void DiskCacheBackendTest::BackendSetSize() {
- SetDirectMode();
const int cache_size = 0x10000; // 64 kB
SetMaxSize(cache_size);
InitCache();
@@ -644,7 +629,6 @@
TEST_F(DiskCacheBackendTest, NewEvictionTrim) {
SetNewEviction();
- SetDirectMode();
InitCache();
disk_cache::Entry* entry;
@@ -675,7 +659,6 @@
// Before looking for invalid entries, let's check a valid entry.
void DiskCacheBackendTest::BackendValidEntry() {
- SetDirectMode();
InitCache();
std::string key("Some key");
@@ -712,8 +695,6 @@
// entry to be invalid, simulating a crash in the middle.
// We'll be leaking memory from this test.
void DiskCacheBackendTest::BackendInvalidEntry() {
- // Use the implementation directly... we need to simulate a crash.
- SetDirectMode();
InitCache();
std::string key("Some key");
@@ -761,8 +742,6 @@
// Almost the same test, but this time crash the cache after reading an entry.
// We'll be leaking memory from this test.
void DiskCacheBackendTest::BackendInvalidEntryRead() {
- // Use the implementation directly... we need to simulate a crash.
- SetDirectMode();
InitCache();
std::string key("Some key");
@@ -888,9 +867,6 @@
// We'll be leaking memory from this test.
void DiskCacheBackendTest::BackendTrimInvalidEntry() {
- // Use the implementation directly... we need to simulate a crash.
- SetDirectMode();
-
const int kSize = 0x3000; // 12 kB
SetMaxSize(kSize * 10);
InitCache();
@@ -943,8 +919,6 @@
// We'll be leaking memory from this test.
void DiskCacheBackendTest::BackendTrimInvalidEntry2() {
- // Use the implementation directly... we need to simulate a crash.
- SetDirectMode();
SetMask(0xf); // 16-entry table.
const int kSize = 0x3000; // 12 kB
@@ -1186,8 +1160,6 @@
// Verify handling of invalid entries while doing enumerations.
// We'll be leaking memory from this test.
void DiskCacheBackendTest::BackendInvalidEntryEnumeration() {
- // Use the implementation directly... we need to simulate a crash.
- SetDirectMode();
InitCache();
std::string key("Some key");
@@ -1546,28 +1518,28 @@
BackendRecoverWithEviction();
}
-// Tests dealing with cache files that cannot be recovered.
-TEST_F(DiskCacheTest, DeleteOld) {
+// Tests that the |BackendImpl| fails to start with the wrong cache version.
+TEST_F(DiskCacheTest, WrongVersion) {
ASSERT_TRUE(CopyTestCache("wrong_version"));
base::Thread cache_thread("CacheThread");
ASSERT_TRUE(cache_thread.StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0)));
net::TestCompletionCallback cb;
- disk_cache::Backend* cache;
- int rv = disk_cache::BackendImpl::CreateBackend(
- cache_path_, true, 0, net::DISK_CACHE, disk_cache::kNoRandom,
- cache_thread.message_loop_proxy(), NULL, &cache, cb.callback());
- ASSERT_EQ(net::OK, cb.GetResult(rv));
+ disk_cache::BackendImpl* cache = new disk_cache::BackendImpl(
+ cache_path_, cache_thread.message_loop_proxy(), NULL);
+ int rv = cache->Init(cb.callback());
+ ASSERT_EQ(net::ERR_FAILED, cb.GetResult(rv));
- MessageLoopHelper helper;
-
- ASSERT_TRUE(NULL != cache);
- ASSERT_EQ(0, cache->GetEntryCount());
-
delete cache;
}
+// Tests that the cache is properly restarted on recovery error.
+TEST_F(DiskCacheBackendTest, DeleteOld) {
+ ASSERT_TRUE(CopyTestCache("wrong_version"));
+ InitDefaultCacheViaCreator();
+}
+
// We want to be able to deal with messed up entries on disk.
void DiskCacheBackendTest::BackendInvalidEntry2() {
ASSERT_TRUE(CopyTestCache("bad_entry"));
@@ -1719,7 +1691,6 @@
// Tests handling of corrupt entries by keeping the rankings node around, with
// a fatal failure.
void DiskCacheBackendTest::BackendInvalidEntry7() {
- SetDirectMode();
const int kSize = 0x3000; // 12 kB.
SetMaxSize(kSize * 10);
InitCache();
@@ -1764,7 +1735,6 @@
// Tests handling of corrupt entries by keeping the rankings node around, with
// a non fatal failure.
void DiskCacheBackendTest::BackendInvalidEntry8() {
- SetDirectMode();
const int kSize = 0x3000; // 12 kB
SetMaxSize(kSize * 10);
InitCache();
@@ -1812,7 +1782,6 @@
// codepaths so they are tighlty coupled with the code, but that is better than
// not testing error handling code.
void DiskCacheBackendTest::BackendInvalidEntry9(bool eviction) {
- SetDirectMode();
const int kSize = 0x3000; // 12 kB.
SetMaxSize(kSize * 10);
InitCache();
@@ -1877,7 +1846,6 @@
// Tests handling of corrupt entries detected by enumerations.
void DiskCacheBackendTest::BackendInvalidEntry10(bool eviction) {
- SetDirectMode();
const int kSize = 0x3000; // 12 kB.
SetMaxSize(kSize * 10);
SetNewEviction();
@@ -1941,7 +1909,6 @@
// Tests handling of corrupt entries detected by enumerations.
void DiskCacheBackendTest::BackendInvalidEntry11(bool eviction) {
- SetDirectMode();
const int kSize = 0x3000; // 12 kB.
SetMaxSize(kSize * 10);
SetNewEviction();
@@ -2013,7 +1980,6 @@
// Tests handling of corrupt entries in the middle of a long eviction run.
void DiskCacheBackendTest::BackendTrimInvalidEntry12() {
- SetDirectMode();
const int kSize = 0x3000; // 12 kB
SetMaxSize(kSize * 10);
InitCache();
@@ -2090,7 +2056,6 @@
TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) {
ASSERT_TRUE(CopyTestCache("bad_rankings"));
DisableFirstCleanup();
- SetDirectMode();
InitCache();
BackendInvalidRankings();
}
@@ -2098,7 +2063,6 @@
TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsSuccess) {
ASSERT_TRUE(CopyTestCache("bad_rankings"));
DisableFirstCleanup();
- SetDirectMode();
SetNewEviction();
InitCache();
BackendInvalidRankings();
@@ -2107,7 +2071,6 @@
TEST_F(DiskCacheBackendTest, InvalidRankingsFailure) {
ASSERT_TRUE(CopyTestCache("bad_rankings"));
DisableFirstCleanup();
- SetDirectMode();
InitCache();
SetTestMode(); // Fail cache reinitialization.
BackendInvalidRankings();
@@ -2116,7 +2079,6 @@
TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsFailure) {
ASSERT_TRUE(CopyTestCache("bad_rankings"));
DisableFirstCleanup();
- SetDirectMode();
SetNewEviction();
InitCache();
SetTestMode(); // Fail cache reinitialization.
@@ -2143,7 +2105,6 @@
TEST_F(DiskCacheBackendTest, DisableSuccess) {
ASSERT_TRUE(CopyTestCache("bad_rankings"));
DisableFirstCleanup();
- SetDirectMode();
InitCache();
BackendDisable();
}
@@ -2151,7 +2112,6 @@
TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess) {
ASSERT_TRUE(CopyTestCache("bad_rankings"));
DisableFirstCleanup();
- SetDirectMode();
SetNewEviction();
InitCache();
BackendDisable();
@@ -2160,7 +2120,6 @@
TEST_F(DiskCacheBackendTest, DisableFailure) {
ASSERT_TRUE(CopyTestCache("bad_rankings"));
DisableFirstCleanup();
- SetDirectMode();
InitCache();
SetTestMode(); // Fail cache reinitialization.
BackendDisable();
@@ -2169,7 +2128,6 @@
TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure) {
ASSERT_TRUE(CopyTestCache("bad_rankings"));
DisableFirstCleanup();
- SetDirectMode();
SetNewEviction();
InitCache();
SetTestMode(); // Fail cache reinitialization.
@@ -2197,7 +2155,6 @@
TEST_F(DiskCacheBackendTest, DisableSuccess2) {
ASSERT_TRUE(CopyTestCache("list_loop"));
DisableFirstCleanup();
- SetDirectMode();
InitCache();
BackendDisable2();
}
@@ -2206,7 +2163,6 @@
ASSERT_TRUE(CopyTestCache("list_loop"));
DisableFirstCleanup();
SetNewEviction();
- SetDirectMode();
InitCache();
BackendDisable2();
}
@@ -2214,7 +2170,6 @@
TEST_F(DiskCacheBackendTest, DisableFailure2) {
ASSERT_TRUE(CopyTestCache("list_loop"));
DisableFirstCleanup();
- SetDirectMode();
InitCache();
SetTestMode(); // Fail cache reinitialization.
BackendDisable2();
@@ -2223,7 +2178,6 @@
TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure2) {
ASSERT_TRUE(CopyTestCache("list_loop"));
DisableFirstCleanup();
- SetDirectMode();
SetNewEviction();
InitCache();
SetTestMode(); // Fail cache reinitialization.
@@ -2316,7 +2270,6 @@
TEST_F(DiskCacheBackendTest, DisableSuccess4) {
ASSERT_TRUE(CopyTestCache("bad_rankings"));
DisableFirstCleanup();
- SetDirectMode();
InitCache();
BackendDisable4();
}
@@ -2324,7 +2277,6 @@
TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess4) {
ASSERT_TRUE(CopyTestCache("bad_rankings"));
DisableFirstCleanup();
- SetDirectMode();
SetNewEviction();
InitCache();
BackendDisable4();
@@ -2460,12 +2412,12 @@
const int kNumberOfCaches = 2;
disk_cache::Backend* cache[kNumberOfCaches];
- int rv = disk_cache::BackendImpl::CreateBackend(
- store1.path(), false, 0, net::DISK_CACHE, disk_cache::kNone,
+ int rv = disk_cache::CreateCacheBackend(
+ net::DISK_CACHE, store1.path(), 0, false,
cache_thread.message_loop_proxy(), NULL, &cache[0], cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
- rv = disk_cache::BackendImpl::CreateBackend(
- store2.path(), false, 0, net::MEDIA_CACHE, disk_cache::kNone,
+ rv = disk_cache::CreateCacheBackend(
+ net::MEDIA_CACHE, store2.path(), 0, false,
cache_thread.message_loop_proxy(), NULL, &cache[1], cb.callback());
ASSERT_EQ(net::OK, cb.GetResult(rv));
@@ -2534,7 +2486,6 @@
// Tests that we can "migrate" a running instance from one experiment group to
// another.
TEST_F(DiskCacheBackendTest, Histograms) {
- SetDirectMode();
InitCache();
disk_cache::BackendImpl* backend_ = cache_impl_; // Needed be the macro.
@@ -2546,7 +2497,6 @@
// Make sure that we keep the total memory used by the internal buffers under
// control.
TEST_F(DiskCacheBackendTest, TotalBuffersSize1) {
- SetDirectMode();
InitCache();
std::string key("the first key");
disk_cache::Entry* entry;
@@ -2579,7 +2529,6 @@
// This test assumes at least 150MB of system memory.
TEST_F(DiskCacheBackendTest, TotalBuffersSize2) {
- SetDirectMode();
InitCache();
const int kOneMB = 1024 * 1024;
@@ -2607,7 +2556,6 @@
// Tests that sharing of external files works and we are able to delete the
// files when we need to.
TEST_F(DiskCacheBackendTest, FileSharing) {
- SetDirectMode();
InitCache();
disk_cache::Addr address(0x80000001);
@@ -2646,7 +2594,6 @@
}
TEST_F(DiskCacheBackendTest, UpdateRankForExternalCacheHit) {
- SetDirectMode();
InitCache();
disk_cache::Entry* entry;
@@ -2670,7 +2617,6 @@
TEST_F(DiskCacheBackendTest, ShaderCacheUpdateRankForExternalCacheHit) {
SetCacheType(net::SHADER_CACHE);
- SetDirectMode();
InitCache();
disk_cache::Entry* entry;

Powered by Google App Engine
This is Rietveld 408576698