[email protected] | 05f8087d | 2012-06-29 18:58:37 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
| 5 | #include "net/disk_cache/disk_cache_test_base.h" |
| 6 | |
[email protected] | 79b3fec | 2011-11-15 22:33:47 | [diff] [blame] | 7 | #include "base/file_util.h" |
| 8 | #include "base/path_service.h" |
[email protected] | 94a9d1a | 2013-03-24 09:50:31 | [diff] [blame] | 9 | #include "base/run_loop.h" |
[email protected] | e1fcf14 | 2010-08-23 18:47:25 | [diff] [blame] | 10 | #include "net/base/io_buffer.h" |
[email protected] | fb2622f | 2010-07-13 18:00:56 | [diff] [blame] | 11 | #include "net/base/net_errors.h" |
[email protected] | bc4fb8e | 2010-03-18 23:58:17 | [diff] [blame] | 12 | #include "net/base/test_completion_callback.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 13 | #include "net/disk_cache/backend_impl.h" |
[email protected] | 398ad13 | 2013-04-02 15:11:01 | [diff] [blame] | 14 | #include "net/disk_cache/cache_util.h" |
| 15 | #include "net/disk_cache/disk_cache.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 16 | #include "net/disk_cache/disk_cache_test_util.h" |
| 17 | #include "net/disk_cache/mem_backend_impl.h" |
[email protected] | 398ad13 | 2013-04-02 15:11:01 | [diff] [blame] | 18 | #include "net/disk_cache/simple/simple_backend_impl.h" |
[email protected] | 7e48c1b | 2013-07-12 12:15:43 | [diff] [blame^] | 19 | #include "net/disk_cache/simple/simple_index.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 20 | |
[email protected] | 79b3fec | 2011-11-15 22:33:47 | [diff] [blame] | 21 | DiskCacheTest::DiskCacheTest() { |
[email protected] | 784f930 | 2012-08-17 00:13:43 | [diff] [blame] | 22 | CHECK(temp_dir_.CreateUniqueTempDir()); |
| 23 | cache_path_ = temp_dir_.path(); |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 24 | if (!base::MessageLoop::current()) |
| 25 | message_loop_.reset(new base::MessageLoopForIO()); |
[email protected] | 79b3fec | 2011-11-15 22:33:47 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | DiskCacheTest::~DiskCacheTest() { |
| 29 | } |
| 30 | |
| 31 | bool DiskCacheTest::CopyTestCache(const std::string& name) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 32 | base::FilePath path; |
[email protected] | 79b3fec | 2011-11-15 22:33:47 | [diff] [blame] | 33 | PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 34 | path = path.AppendASCII("net"); |
| 35 | path = path.AppendASCII("data"); |
| 36 | path = path.AppendASCII("cache_tests"); |
| 37 | path = path.AppendASCII(name); |
| 38 | |
| 39 | if (!CleanupCacheDir()) |
| 40 | return false; |
[email protected] | f0ff2ad | 2013-07-09 17:42:26 | [diff] [blame] | 41 | return base::CopyDirectory(path, cache_path_, false); |
[email protected] | 79b3fec | 2011-11-15 22:33:47 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | bool DiskCacheTest::CleanupCacheDir() { |
| 45 | return DeleteCache(cache_path_); |
| 46 | } |
| 47 | |
[email protected] | 17b8914 | 2008-11-07 21:52:15 | [diff] [blame] | 48 | void DiskCacheTest::TearDown() { |
[email protected] | 94a9d1a | 2013-03-24 09:50:31 | [diff] [blame] | 49 | base::RunLoop().RunUntilIdle(); |
[email protected] | 17b8914 | 2008-11-07 21:52:15 | [diff] [blame] | 50 | } |
| 51 | |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 52 | DiskCacheTestWithCache::DiskCacheTestWithCache() |
| 53 | : cache_(NULL), |
| 54 | cache_impl_(NULL), |
[email protected] | 1ed9575 | 2013-04-23 00:12:36 | [diff] [blame] | 55 | simple_cache_impl_(NULL), |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 56 | mem_cache_(NULL), |
| 57 | mask_(0), |
| 58 | size_(0), |
| 59 | type_(net::DISK_CACHE), |
| 60 | memory_only_(false), |
[email protected] | 398ad13 | 2013-04-02 15:11:01 | [diff] [blame] | 61 | simple_cache_mode_(false), |
[email protected] | 7e48c1b | 2013-07-12 12:15:43 | [diff] [blame^] | 62 | simple_cache_wait_for_index_(true), |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 63 | force_creation_(false), |
| 64 | new_eviction_(false), |
| 65 | first_cleanup_(true), |
| 66 | integrity_(true), |
| 67 | use_current_thread_(false), |
| 68 | cache_thread_("CacheThread") { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 69 | } |
| 70 | |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 71 | DiskCacheTestWithCache::~DiskCacheTestWithCache() {} |
| 72 | |
[email protected] | 4d5e036 | 2008-08-28 00:59:06 | [diff] [blame] | 73 | void DiskCacheTestWithCache::InitCache() { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 74 | if (memory_only_) |
| 75 | InitMemoryCache(); |
| 76 | else |
| 77 | InitDiskCache(); |
| 78 | |
| 79 | ASSERT_TRUE(NULL != cache_); |
[email protected] | a255384 | 2013-04-19 14:25:18 | [diff] [blame] | 80 | if (first_cleanup_) |
[email protected] | a9da16d | 2008-07-30 21:41:54 | [diff] [blame] | 81 | ASSERT_EQ(0, cache_->GetEntryCount()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 82 | } |
| 83 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 84 | // We are expected to leak memory when simulating crashes. |
[email protected] | 4d5e036 | 2008-08-28 00:59:06 | [diff] [blame] | 85 | void DiskCacheTestWithCache::SimulateCrash() { |
[email protected] | 398ad13 | 2013-04-02 15:11:01 | [diff] [blame] | 86 | ASSERT_TRUE(!memory_only_); |
[email protected] | 2a65aceb8 | 2011-12-19 20:59:27 | [diff] [blame] | 87 | net::TestCompletionCallback cb; |
| 88 | int rv = cache_impl_->FlushQueueForTest(cb.callback()); |
[email protected] | fb2622f | 2010-07-13 18:00:56 | [diff] [blame] | 89 | ASSERT_EQ(net::OK, cb.GetResult(rv)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 90 | cache_impl_->ClearRefCountForTest(); |
| 91 | |
| 92 | delete cache_impl_; |
[email protected] | 79b3fec | 2011-11-15 22:33:47 | [diff] [blame] | 93 | EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 94 | |
[email protected] | 398ad13 | 2013-04-02 15:11:01 | [diff] [blame] | 95 | CreateBackend(disk_cache::kNoRandom, &cache_thread_); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 96 | } |
[email protected] | a9da16d | 2008-07-30 21:41:54 | [diff] [blame] | 97 | |
[email protected] | 4d5e036 | 2008-08-28 00:59:06 | [diff] [blame] | 98 | void DiskCacheTestWithCache::SetTestMode() { |
[email protected] | 398ad13 | 2013-04-02 15:11:01 | [diff] [blame] | 99 | ASSERT_TRUE(!memory_only_); |
[email protected] | a9da16d | 2008-07-30 21:41:54 | [diff] [blame] | 100 | cache_impl_->SetUnitTestMode(); |
| 101 | } |
[email protected] | bc4fb8e | 2010-03-18 23:58:17 | [diff] [blame] | 102 | |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 103 | void DiskCacheTestWithCache::SetMaxSize(int size) { |
| 104 | size_ = size; |
[email protected] | 1ed9575 | 2013-04-23 00:12:36 | [diff] [blame] | 105 | if (simple_cache_impl_) |
| 106 | EXPECT_TRUE(simple_cache_impl_->SetMaxSize(size)); |
| 107 | |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 108 | if (cache_impl_) |
| 109 | EXPECT_TRUE(cache_impl_->SetMaxSize(size)); |
| 110 | |
| 111 | if (mem_cache_) |
| 112 | EXPECT_TRUE(mem_cache_->SetMaxSize(size)); |
| 113 | } |
| 114 | |
[email protected] | bc4fb8e | 2010-03-18 23:58:17 | [diff] [blame] | 115 | int DiskCacheTestWithCache::OpenEntry(const std::string& key, |
| 116 | disk_cache::Entry** entry) { |
[email protected] | 2a65aceb8 | 2011-12-19 20:59:27 | [diff] [blame] | 117 | net::TestCompletionCallback cb; |
| 118 | int rv = cache_->OpenEntry(key, entry, cb.callback()); |
[email protected] | bc4fb8e | 2010-03-18 23:58:17 | [diff] [blame] | 119 | return cb.GetResult(rv); |
| 120 | } |
| 121 | |
| 122 | int DiskCacheTestWithCache::CreateEntry(const std::string& key, |
| 123 | disk_cache::Entry** entry) { |
[email protected] | 2a65aceb8 | 2011-12-19 20:59:27 | [diff] [blame] | 124 | net::TestCompletionCallback cb; |
| 125 | int rv = cache_->CreateEntry(key, entry, cb.callback()); |
[email protected] | bc4fb8e | 2010-03-18 23:58:17 | [diff] [blame] | 126 | return cb.GetResult(rv); |
| 127 | } |
| 128 | |
| 129 | int DiskCacheTestWithCache::DoomEntry(const std::string& key) { |
[email protected] | 42c45963 | 2011-12-17 02:20:23 | [diff] [blame] | 130 | net::TestCompletionCallback cb; |
| 131 | int rv = cache_->DoomEntry(key, cb.callback()); |
[email protected] | bc4fb8e | 2010-03-18 23:58:17 | [diff] [blame] | 132 | return cb.GetResult(rv); |
| 133 | } |
| 134 | |
| 135 | int DiskCacheTestWithCache::DoomAllEntries() { |
[email protected] | 6ad7c091 | 2011-12-15 19:10:19 | [diff] [blame] | 136 | net::TestCompletionCallback cb; |
| 137 | int rv = cache_->DoomAllEntries(cb.callback()); |
[email protected] | bc4fb8e | 2010-03-18 23:58:17 | [diff] [blame] | 138 | return cb.GetResult(rv); |
| 139 | } |
| 140 | |
| 141 | int DiskCacheTestWithCache::DoomEntriesBetween(const base::Time initial_time, |
| 142 | const base::Time end_time) { |
[email protected] | 6ad7c091 | 2011-12-15 19:10:19 | [diff] [blame] | 143 | net::TestCompletionCallback cb; |
| 144 | int rv = cache_->DoomEntriesBetween(initial_time, end_time, cb.callback()); |
[email protected] | bc4fb8e | 2010-03-18 23:58:17 | [diff] [blame] | 145 | return cb.GetResult(rv); |
| 146 | } |
| 147 | |
| 148 | int DiskCacheTestWithCache::DoomEntriesSince(const base::Time initial_time) { |
[email protected] | 2a65aceb8 | 2011-12-19 20:59:27 | [diff] [blame] | 149 | net::TestCompletionCallback cb; |
| 150 | int rv = cache_->DoomEntriesSince(initial_time, cb.callback()); |
[email protected] | bc4fb8e | 2010-03-18 23:58:17 | [diff] [blame] | 151 | return cb.GetResult(rv); |
| 152 | } |
| 153 | |
| 154 | int DiskCacheTestWithCache::OpenNextEntry(void** iter, |
| 155 | disk_cache::Entry** next_entry) { |
[email protected] | 6ad7c091 | 2011-12-15 19:10:19 | [diff] [blame] | 156 | net::TestCompletionCallback cb; |
| 157 | int rv = cache_->OpenNextEntry(iter, next_entry, cb.callback()); |
[email protected] | bc4fb8e | 2010-03-18 23:58:17 | [diff] [blame] | 158 | return cb.GetResult(rv); |
| 159 | } |
[email protected] | fb2622f | 2010-07-13 18:00:56 | [diff] [blame] | 160 | |
| 161 | void DiskCacheTestWithCache::FlushQueueForTest() { |
| 162 | if (memory_only_ || !cache_impl_) |
| 163 | return; |
| 164 | |
[email protected] | 2a65aceb8 | 2011-12-19 20:59:27 | [diff] [blame] | 165 | net::TestCompletionCallback cb; |
| 166 | int rv = cache_impl_->FlushQueueForTest(cb.callback()); |
[email protected] | fb2622f | 2010-07-13 18:00:56 | [diff] [blame] | 167 | EXPECT_EQ(net::OK, cb.GetResult(rv)); |
| 168 | } |
[email protected] | e1fcf14 | 2010-08-23 18:47:25 | [diff] [blame] | 169 | |
[email protected] | f27bbe00 | 2011-12-22 11:29:34 | [diff] [blame] | 170 | void DiskCacheTestWithCache::RunTaskForTest(const base::Closure& closure) { |
[email protected] | 65188eb | 2010-09-16 20:59:29 | [diff] [blame] | 171 | if (memory_only_ || !cache_impl_) { |
[email protected] | f27bbe00 | 2011-12-22 11:29:34 | [diff] [blame] | 172 | closure.Run(); |
[email protected] | 65188eb | 2010-09-16 20:59:29 | [diff] [blame] | 173 | return; |
| 174 | } |
| 175 | |
[email protected] | 2a65aceb8 | 2011-12-19 20:59:27 | [diff] [blame] | 176 | net::TestCompletionCallback cb; |
[email protected] | f27bbe00 | 2011-12-22 11:29:34 | [diff] [blame] | 177 | int rv = cache_impl_->RunTaskForTest(closure, cb.callback()); |
[email protected] | 65188eb | 2010-09-16 20:59:29 | [diff] [blame] | 178 | EXPECT_EQ(net::OK, cb.GetResult(rv)); |
| 179 | } |
| 180 | |
[email protected] | e1fcf14 | 2010-08-23 18:47:25 | [diff] [blame] | 181 | int DiskCacheTestWithCache::ReadData(disk_cache::Entry* entry, int index, |
| 182 | int offset, net::IOBuffer* buf, int len) { |
[email protected] | 2a65aceb8 | 2011-12-19 20:59:27 | [diff] [blame] | 183 | net::TestCompletionCallback cb; |
| 184 | int rv = entry->ReadData(index, offset, buf, len, cb.callback()); |
[email protected] | e1fcf14 | 2010-08-23 18:47:25 | [diff] [blame] | 185 | return cb.GetResult(rv); |
| 186 | } |
| 187 | |
[email protected] | e1fcf14 | 2010-08-23 18:47:25 | [diff] [blame] | 188 | int DiskCacheTestWithCache::WriteData(disk_cache::Entry* entry, int index, |
| 189 | int offset, net::IOBuffer* buf, int len, |
| 190 | bool truncate) { |
[email protected] | 2a65aceb8 | 2011-12-19 20:59:27 | [diff] [blame] | 191 | net::TestCompletionCallback cb; |
| 192 | int rv = entry->WriteData(index, offset, buf, len, cb.callback(), truncate); |
[email protected] | e1fcf14 | 2010-08-23 18:47:25 | [diff] [blame] | 193 | return cb.GetResult(rv); |
| 194 | } |
| 195 | |
| 196 | int DiskCacheTestWithCache::ReadSparseData(disk_cache::Entry* entry, |
| 197 | int64 offset, net::IOBuffer* buf, |
| 198 | int len) { |
[email protected] | 2a65aceb8 | 2011-12-19 20:59:27 | [diff] [blame] | 199 | net::TestCompletionCallback cb; |
| 200 | int rv = entry->ReadSparseData(offset, buf, len, cb.callback()); |
[email protected] | e1fcf14 | 2010-08-23 18:47:25 | [diff] [blame] | 201 | return cb.GetResult(rv); |
| 202 | } |
| 203 | |
| 204 | int DiskCacheTestWithCache::WriteSparseData(disk_cache::Entry* entry, |
| 205 | int64 offset, |
| 206 | net::IOBuffer* buf, int len) { |
[email protected] | 2a65aceb8 | 2011-12-19 20:59:27 | [diff] [blame] | 207 | net::TestCompletionCallback cb; |
| 208 | int rv = entry->WriteSparseData(offset, buf, len, cb.callback()); |
[email protected] | e1fcf14 | 2010-08-23 18:47:25 | [diff] [blame] | 209 | return cb.GetResult(rv); |
| 210 | } |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 211 | |
[email protected] | ceb61da3 | 2011-01-25 23:52:02 | [diff] [blame] | 212 | void DiskCacheTestWithCache::TrimForTest(bool empty) { |
[email protected] | f27bbe00 | 2011-12-22 11:29:34 | [diff] [blame] | 213 | RunTaskForTest(base::Bind(&disk_cache::BackendImpl::TrimForTest, |
| 214 | base::Unretained(cache_impl_), |
| 215 | empty)); |
[email protected] | ceb61da3 | 2011-01-25 23:52:02 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | void DiskCacheTestWithCache::TrimDeletedListForTest(bool empty) { |
[email protected] | f27bbe00 | 2011-12-22 11:29:34 | [diff] [blame] | 219 | RunTaskForTest(base::Bind(&disk_cache::BackendImpl::TrimDeletedListForTest, |
| 220 | base::Unretained(cache_impl_), |
| 221 | empty)); |
[email protected] | ceb61da3 | 2011-01-25 23:52:02 | [diff] [blame] | 222 | } |
| 223 | |
[email protected] | 05f8087d | 2012-06-29 18:58:37 | [diff] [blame] | 224 | void DiskCacheTestWithCache::AddDelay() { |
| 225 | base::Time initial = base::Time::Now(); |
| 226 | while (base::Time::Now() <= initial) { |
| 227 | base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); |
| 228 | }; |
| 229 | } |
| 230 | |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 231 | void DiskCacheTestWithCache::TearDown() { |
[email protected] | 94a9d1a | 2013-03-24 09:50:31 | [diff] [blame] | 232 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 233 | delete cache_; |
| 234 | if (cache_thread_.IsRunning()) |
| 235 | cache_thread_.Stop(); |
| 236 | |
[email protected] | fccce90 | 2013-04-15 19:00:51 | [diff] [blame] | 237 | if (!memory_only_ && !simple_cache_mode_ && integrity_) { |
[email protected] | 79b3fec | 2011-11-15 22:33:47 | [diff] [blame] | 238 | EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_)); |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | PlatformTest::TearDown(); |
| 242 | } |
| 243 | |
| 244 | void DiskCacheTestWithCache::InitMemoryCache() { |
[email protected] | 9eb8cdf | 2011-03-17 18:53:02 | [diff] [blame] | 245 | mem_cache_ = new disk_cache::MemBackendImpl(NULL); |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 246 | cache_ = mem_cache_; |
| 247 | ASSERT_TRUE(NULL != cache_); |
| 248 | |
| 249 | if (size_) |
| 250 | EXPECT_TRUE(mem_cache_->SetMaxSize(size_)); |
| 251 | |
| 252 | ASSERT_TRUE(mem_cache_->Init()); |
| 253 | } |
| 254 | |
| 255 | void DiskCacheTestWithCache::InitDiskCache() { |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 256 | if (first_cleanup_) |
[email protected] | 79b3fec | 2011-11-15 22:33:47 | [diff] [blame] | 257 | ASSERT_TRUE(CleanupCacheDir()); |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 258 | |
| 259 | if (!cache_thread_.IsRunning()) { |
[email protected] | 398ad13 | 2013-04-02 15:11:01 | [diff] [blame] | 260 | ASSERT_TRUE(cache_thread_.StartWithOptions( |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 261 | base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 262 | } |
| 263 | ASSERT_TRUE(cache_thread_.message_loop() != NULL); |
| 264 | |
[email protected] | 398ad13 | 2013-04-02 15:11:01 | [diff] [blame] | 265 | CreateBackend(disk_cache::kNoRandom, &cache_thread_); |
| 266 | } |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 267 | |
[email protected] | 398ad13 | 2013-04-02 15:11:01 | [diff] [blame] | 268 | void DiskCacheTestWithCache::CreateBackend(uint32 flags, base::Thread* thread) { |
| 269 | base::MessageLoopProxy* runner; |
| 270 | if (use_current_thread_) |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 271 | runner = base::MessageLoopProxy::current().get(); |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 272 | else |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 273 | runner = thread->message_loop_proxy().get(); |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 274 | |
[email protected] | 398ad13 | 2013-04-02 15:11:01 | [diff] [blame] | 275 | if (simple_cache_mode_) { |
| 276 | net::TestCompletionCallback cb; |
[email protected] | 00831c82 | 2013-04-10 15:37:12 | [diff] [blame] | 277 | disk_cache::SimpleBackendImpl* simple_backend = |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 278 | new disk_cache::SimpleBackendImpl( |
| 279 | cache_path_, size_, type_, make_scoped_refptr(runner).get(), NULL); |
[email protected] | 00831c82 | 2013-04-10 15:37:12 | [diff] [blame] | 280 | int rv = simple_backend->Init(cb.callback()); |
[email protected] | 398ad13 | 2013-04-02 15:11:01 | [diff] [blame] | 281 | ASSERT_EQ(net::OK, cb.GetResult(rv)); |
[email protected] | 1ed9575 | 2013-04-23 00:12:36 | [diff] [blame] | 282 | cache_ = simple_cache_impl_ = simple_backend; |
[email protected] | 7e48c1b | 2013-07-12 12:15:43 | [diff] [blame^] | 283 | if (simple_cache_wait_for_index_) { |
| 284 | net::TestCompletionCallback wait_for_index_cb; |
| 285 | rv = simple_backend->index()->ExecuteWhenReady( |
| 286 | wait_for_index_cb.callback()); |
| 287 | ASSERT_EQ(net::OK, wait_for_index_cb.GetResult(rv)); |
| 288 | } |
[email protected] | 398ad13 | 2013-04-02 15:11:01 | [diff] [blame] | 289 | return; |
| 290 | } |
| 291 | |
| 292 | if (mask_) |
| 293 | cache_impl_ = new disk_cache::BackendImpl(cache_path_, mask_, runner, NULL); |
| 294 | else |
| 295 | cache_impl_ = new disk_cache::BackendImpl(cache_path_, runner, NULL); |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 296 | cache_ = cache_impl_; |
| 297 | ASSERT_TRUE(NULL != cache_); |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 298 | if (size_) |
| 299 | EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 300 | if (new_eviction_) |
| 301 | cache_impl_->SetNewEviction(); |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 302 | cache_impl_->SetType(type_); |
[email protected] | 398ad13 | 2013-04-02 15:11:01 | [diff] [blame] | 303 | cache_impl_->SetFlags(flags); |
[email protected] | 42c45963 | 2011-12-17 02:20:23 | [diff] [blame] | 304 | net::TestCompletionCallback cb; |
| 305 | int rv = cache_impl_->Init(cb.callback()); |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 306 | ASSERT_EQ(net::OK, cb.GetResult(rv)); |
[email protected] | 398ad13 | 2013-04-02 15:11:01 | [diff] [blame] | 307 | cache_ = cache_impl_; |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 308 | } |