| Index: net/disk_cache/disk_cache_test_base.cc
|
| diff --git a/net/disk_cache/disk_cache_test_base.cc b/net/disk_cache/disk_cache_test_base.cc
|
| index 6c9b91c66617cd50c2ae4f725f1dba4f8123ec62..3860667cd0ecf0005dda3004d1e21c1ccedadcb4 100644
|
| --- a/net/disk_cache/disk_cache_test_base.cc
|
| +++ b/net/disk_cache/disk_cache_test_base.cc
|
| @@ -15,15 +15,25 @@ void DiskCacheTest::TearDown() {
|
| MessageLoop::current()->RunAllPending();
|
| }
|
|
|
| -void DiskCacheTestWithCache::SetMaxSize(int size) {
|
| - size_ = size;
|
| - if (cache_impl_)
|
| - EXPECT_TRUE(cache_impl_->SetMaxSize(size));
|
| -
|
| - if (mem_cache_)
|
| - EXPECT_TRUE(mem_cache_->SetMaxSize(size));
|
| +DiskCacheTestWithCache::DiskCacheTestWithCache()
|
| + : cache_(NULL),
|
| + cache_impl_(NULL),
|
| + mem_cache_(NULL),
|
| + mask_(0),
|
| + size_(0),
|
| + type_(net::DISK_CACHE),
|
| + memory_only_(false),
|
| + implementation_(false),
|
| + force_creation_(false),
|
| + new_eviction_(false),
|
| + first_cleanup_(true),
|
| + integrity_(true),
|
| + use_current_thread_(false),
|
| + cache_thread_("CacheThread") {
|
| }
|
|
|
| +DiskCacheTestWithCache::~DiskCacheTestWithCache() {}
|
| +
|
| void DiskCacheTestWithCache::InitCache() {
|
| if (mask_ || new_eviction_)
|
| implementation_ = true;
|
| @@ -38,86 +48,6 @@ void DiskCacheTestWithCache::InitCache() {
|
| ASSERT_EQ(0, cache_->GetEntryCount());
|
| }
|
|
|
| -void DiskCacheTestWithCache::InitMemoryCache() {
|
| - if (!implementation_) {
|
| - cache_ = disk_cache::MemBackendImpl::CreateBackend(size_);
|
| - return;
|
| - }
|
| -
|
| - mem_cache_ = new disk_cache::MemBackendImpl();
|
| - cache_ = mem_cache_;
|
| - ASSERT_TRUE(NULL != cache_);
|
| -
|
| - if (size_)
|
| - EXPECT_TRUE(mem_cache_->SetMaxSize(size_));
|
| -
|
| - ASSERT_TRUE(mem_cache_->Init());
|
| -}
|
| -
|
| -void DiskCacheTestWithCache::InitDiskCache() {
|
| - FilePath path = GetCacheFilePath();
|
| - if (first_cleanup_)
|
| - ASSERT_TRUE(DeleteCache(path));
|
| -
|
| - if (!cache_thread_.IsRunning()) {
|
| - EXPECT_TRUE(cache_thread_.StartWithOptions(
|
| - base::Thread::Options(MessageLoop::TYPE_IO, 0)));
|
| - }
|
| - ASSERT_TRUE(cache_thread_.message_loop() != NULL);
|
| -
|
| - if (implementation_)
|
| - return InitDiskCacheImpl(path);
|
| -
|
| - scoped_refptr<base::MessageLoopProxy> thread =
|
| - use_current_thread_ ? base::MessageLoopProxy::CreateForCurrentThread() :
|
| - cache_thread_.message_loop_proxy();
|
| -
|
| - TestCompletionCallback cb;
|
| - int rv = disk_cache::BackendImpl::CreateBackend(
|
| - path, force_creation_, size_, type_,
|
| - disk_cache::kNoRandom, thread, NULL, &cache_, &cb);
|
| - ASSERT_EQ(net::OK, cb.GetResult(rv));
|
| -}
|
| -
|
| -void DiskCacheTestWithCache::InitDiskCacheImpl(const FilePath& path) {
|
| - scoped_refptr<base::MessageLoopProxy> thread =
|
| - use_current_thread_ ? base::MessageLoopProxy::CreateForCurrentThread() :
|
| - cache_thread_.message_loop_proxy();
|
| - if (mask_)
|
| - cache_impl_ = new disk_cache::BackendImpl(path, mask_, thread, NULL);
|
| - else
|
| - cache_impl_ = new disk_cache::BackendImpl(path, thread, NULL);
|
| -
|
| - cache_ = cache_impl_;
|
| - ASSERT_TRUE(NULL != cache_);
|
| -
|
| - if (size_)
|
| - EXPECT_TRUE(cache_impl_->SetMaxSize(size_));
|
| -
|
| - if (new_eviction_)
|
| - cache_impl_->SetNewEviction();
|
| -
|
| - cache_impl_->SetType(type_);
|
| - cache_impl_->SetFlags(disk_cache::kNoRandom);
|
| - TestCompletionCallback cb;
|
| - int rv = cache_impl_->Init(&cb);
|
| - ASSERT_EQ(net::OK, cb.GetResult(rv));
|
| -}
|
| -
|
| -void DiskCacheTestWithCache::TearDown() {
|
| - MessageLoop::current()->RunAllPending();
|
| - delete cache_;
|
| - if (cache_thread_.IsRunning())
|
| - cache_thread_.Stop();
|
| -
|
| - if (!memory_only_ && integrity_) {
|
| - FilePath path = GetCacheFilePath();
|
| - EXPECT_TRUE(CheckCacheIntegrity(path, new_eviction_));
|
| - }
|
| -
|
| - PlatformTest::TearDown();
|
| -}
|
| -
|
| // We are expected to leak memory when simulating crashes.
|
| void DiskCacheTestWithCache::SimulateCrash() {
|
| ASSERT_TRUE(implementation_ && !memory_only_);
|
| @@ -138,6 +68,15 @@ void DiskCacheTestWithCache::SetTestMode() {
|
| cache_impl_->SetUnitTestMode();
|
| }
|
|
|
| +void DiskCacheTestWithCache::SetMaxSize(int size) {
|
| + size_ = size;
|
| + if (cache_impl_)
|
| + EXPECT_TRUE(cache_impl_->SetMaxSize(size));
|
| +
|
| + if (mem_cache_)
|
| + EXPECT_TRUE(mem_cache_->SetMaxSize(size));
|
| +}
|
| +
|
| int DiskCacheTestWithCache::OpenEntry(const std::string& key,
|
| disk_cache::Entry** entry) {
|
| TestCompletionCallback cb;
|
| @@ -236,3 +175,83 @@ int DiskCacheTestWithCache::WriteSparseData(disk_cache::Entry* entry,
|
| int rv = entry->WriteSparseData(offset, buf, len, &cb);
|
| return cb.GetResult(rv);
|
| }
|
| +
|
| +void DiskCacheTestWithCache::TearDown() {
|
| + MessageLoop::current()->RunAllPending();
|
| + delete cache_;
|
| + if (cache_thread_.IsRunning())
|
| + cache_thread_.Stop();
|
| +
|
| + if (!memory_only_ && integrity_) {
|
| + FilePath path = GetCacheFilePath();
|
| + EXPECT_TRUE(CheckCacheIntegrity(path, new_eviction_));
|
| + }
|
| +
|
| + PlatformTest::TearDown();
|
| +}
|
| +
|
| +void DiskCacheTestWithCache::InitMemoryCache() {
|
| + if (!implementation_) {
|
| + cache_ = disk_cache::MemBackendImpl::CreateBackend(size_);
|
| + return;
|
| + }
|
| +
|
| + mem_cache_ = new disk_cache::MemBackendImpl();
|
| + cache_ = mem_cache_;
|
| + ASSERT_TRUE(NULL != cache_);
|
| +
|
| + if (size_)
|
| + EXPECT_TRUE(mem_cache_->SetMaxSize(size_));
|
| +
|
| + ASSERT_TRUE(mem_cache_->Init());
|
| +}
|
| +
|
| +void DiskCacheTestWithCache::InitDiskCache() {
|
| + FilePath path = GetCacheFilePath();
|
| + if (first_cleanup_)
|
| + ASSERT_TRUE(DeleteCache(path));
|
| +
|
| + if (!cache_thread_.IsRunning()) {
|
| + EXPECT_TRUE(cache_thread_.StartWithOptions(
|
| + base::Thread::Options(MessageLoop::TYPE_IO, 0)));
|
| + }
|
| + ASSERT_TRUE(cache_thread_.message_loop() != NULL);
|
| +
|
| + if (implementation_)
|
| + return InitDiskCacheImpl(path);
|
| +
|
| + scoped_refptr<base::MessageLoopProxy> thread =
|
| + use_current_thread_ ? base::MessageLoopProxy::CreateForCurrentThread() :
|
| + cache_thread_.message_loop_proxy();
|
| +
|
| + TestCompletionCallback cb;
|
| + int rv = disk_cache::BackendImpl::CreateBackend(
|
| + path, force_creation_, size_, type_,
|
| + disk_cache::kNoRandom, thread, NULL, &cache_, &cb);
|
| + ASSERT_EQ(net::OK, cb.GetResult(rv));
|
| +}
|
| +
|
| +void DiskCacheTestWithCache::InitDiskCacheImpl(const FilePath& path) {
|
| + scoped_refptr<base::MessageLoopProxy> thread =
|
| + use_current_thread_ ? base::MessageLoopProxy::CreateForCurrentThread() :
|
| + cache_thread_.message_loop_proxy();
|
| + if (mask_)
|
| + cache_impl_ = new disk_cache::BackendImpl(path, mask_, thread, NULL);
|
| + else
|
| + cache_impl_ = new disk_cache::BackendImpl(path, thread, NULL);
|
| +
|
| + cache_ = cache_impl_;
|
| + ASSERT_TRUE(NULL != cache_);
|
| +
|
| + if (size_)
|
| + EXPECT_TRUE(cache_impl_->SetMaxSize(size_));
|
| +
|
| + if (new_eviction_)
|
| + cache_impl_->SetNewEviction();
|
| +
|
| + cache_impl_->SetType(type_);
|
| + cache_impl_->SetFlags(disk_cache::kNoRandom);
|
| + TestCompletionCallback cb;
|
| + int rv = cache_impl_->Init(&cb);
|
| + ASSERT_EQ(net::OK, cb.GetResult(rv));
|
| +}
|
|
|