blob: 5ef965079b178818d00d6bbc6dfe47969a2d1faa [file] [log] [blame]
[email protected]05f8087d2012-06-29 18:58:371// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit586acc5fe2008-07-26 22:42:524
5#include "net/disk_cache/disk_cache_test_base.h"
6
dchengc7eeda422015-12-26 03:56:487#include <utility>
8
thestigd8df0332014-09-04 06:33:299#include "base/files/file_util.h"
[email protected]79b3fec2011-11-15 22:33:4710#include "base/path_service.h"
[email protected]94a9d1a2013-03-24 09:50:3111#include "base/run_loop.h"
[email protected]81e549a2014-08-21 04:19:5512#include "base/single_thread_task_runner.h"
[email protected]8b2f8a52013-08-28 08:45:3513#include "base/threading/platform_thread.h"
gabf767595f2016-05-11 18:50:3514#include "base/threading/thread_task_runner_handle.h"
[email protected]e1fcf142010-08-23 18:47:2515#include "net/base/io_buffer.h"
[email protected]fb2622f2010-07-13 18:00:5616#include "net/base/net_errors.h"
Josh Karlindd9a5d142018-06-06 00:35:4817#include "net/base/request_priority.h"
[email protected]bc4fb8e2010-03-18 23:58:1718#include "net/base/test_completion_callback.h"
Maks Orlovich036fd1f2017-08-07 17:51:1119#include "net/disk_cache/backend_cleanup_tracker.h"
[email protected]c2c5cfc2014-03-03 16:35:2820#include "net/disk_cache/blockfile/backend_impl.h"
[email protected]398ad132013-04-02 15:11:0121#include "net/disk_cache/cache_util.h"
22#include "net/disk_cache/disk_cache.h"
initial.commit586acc5fe2008-07-26 22:42:5223#include "net/disk_cache/disk_cache_test_util.h"
[email protected]c2c5cfc2014-03-03 16:35:2824#include "net/disk_cache/memory/mem_backend_impl.h"
[email protected]398ad132013-04-02 15:11:0125#include "net/disk_cache/simple/simple_backend_impl.h"
Maks Orlovichf378b3a2017-10-31 16:27:3026#include "net/disk_cache/simple/simple_file_tracker.h"
[email protected]7e48c1b2013-07-12 12:15:4327#include "net/disk_cache/simple/simple_index.h"
robpercival214763f2016-07-01 23:27:0128#include "net/test/gtest_util.h"
29#include "testing/gmock/include/gmock/gmock.h"
30#include "testing/gtest/include/gtest/gtest.h"
31
32using net::test::IsOk;
initial.commit586acc5fe2008-07-26 22:42:5233
[email protected]79b3fec2011-11-15 22:33:4734DiskCacheTest::DiskCacheTest() {
[email protected]784f9302012-08-17 00:13:4335 CHECK(temp_dir_.CreateUniqueTempDir());
vabrb8582322016-09-09 08:05:3736 cache_path_ = temp_dir_.GetPath();
[email protected]79b3fec2011-11-15 22:33:4737}
38
Chris Watkins68b15032017-12-01 03:07:1339DiskCacheTest::~DiskCacheTest() = default;
[email protected]79b3fec2011-11-15 22:33:4740
41bool DiskCacheTest::CopyTestCache(const std::string& name) {
[email protected]6cdfd7f2013-02-08 20:40:1542 base::FilePath path;
Avi Drissman5c80d832018-05-01 17:01:1943 base::PathService::Get(base::DIR_SOURCE_ROOT, &path);
[email protected]79b3fec2011-11-15 22:33:4744 path = path.AppendASCII("net");
45 path = path.AppendASCII("data");
46 path = path.AppendASCII("cache_tests");
47 path = path.AppendASCII(name);
48
49 if (!CleanupCacheDir())
50 return false;
[email protected]f0ff2ad2013-07-09 17:42:2651 return base::CopyDirectory(path, cache_path_, false);
[email protected]79b3fec2011-11-15 22:33:4752}
53
54bool DiskCacheTest::CleanupCacheDir() {
55 return DeleteCache(cache_path_);
56}
57
[email protected]17b89142008-11-07 21:52:1558void DiskCacheTest::TearDown() {
[email protected]94a9d1a2013-03-24 09:50:3159 base::RunLoop().RunUntilIdle();
[email protected]17b89142008-11-07 21:52:1560}
61
gavinpb1aaa052014-09-24 14:54:3562DiskCacheTestWithCache::TestIterator::TestIterator(
danakjd04b92d2016-04-16 01:16:4963 std::unique_ptr<disk_cache::Backend::Iterator> iterator)
dchengc7eeda422015-12-26 03:56:4864 : iterator_(std::move(iterator)) {}
gavinpb1aaa052014-09-24 14:54:3565
Chris Watkins68b15032017-12-01 03:07:1366DiskCacheTestWithCache::TestIterator::~TestIterator() = default;
gavinpb1aaa052014-09-24 14:54:3567
68int DiskCacheTestWithCache::TestIterator::OpenNextEntry(
69 disk_cache::Entry** next_entry) {
70 net::TestCompletionCallback cb;
71 int rv = iterator_->OpenNextEntry(next_entry, cb.callback());
72 return cb.GetResult(rv);
73}
74
[email protected]7aefb152011-01-21 23:46:4975DiskCacheTestWithCache::DiskCacheTestWithCache()
[email protected]8c3f5a32013-08-01 11:57:5376 : cache_impl_(NULL),
[email protected]1ed95752013-04-23 00:12:3677 simple_cache_impl_(NULL),
[email protected]7aefb152011-01-21 23:46:4978 mem_cache_(NULL),
79 mask_(0),
80 size_(0),
81 type_(net::DISK_CACHE),
82 memory_only_(false),
[email protected]398ad132013-04-02 15:11:0183 simple_cache_mode_(false),
[email protected]7e48c1b2013-07-12 12:15:4384 simple_cache_wait_for_index_(true),
[email protected]7aefb152011-01-21 23:46:4985 force_creation_(false),
86 new_eviction_(false),
87 first_cleanup_(true),
88 integrity_(true),
Bence Béky98447b12018-05-08 03:14:0189 use_current_thread_(false) {}
initial.commit586acc5fe2008-07-26 22:42:5290
Chris Watkins68b15032017-12-01 03:07:1391DiskCacheTestWithCache::~DiskCacheTestWithCache() = default;
[email protected]7aefb152011-01-21 23:46:4992
[email protected]4d5e0362008-08-28 00:59:0693void DiskCacheTestWithCache::InitCache() {
initial.commit586acc5fe2008-07-26 22:42:5294 if (memory_only_)
95 InitMemoryCache();
96 else
97 InitDiskCache();
98
99 ASSERT_TRUE(NULL != cache_);
[email protected]a2553842013-04-19 14:25:18100 if (first_cleanup_)
[email protected]a9da16d2008-07-30 21:41:54101 ASSERT_EQ(0, cache_->GetEntryCount());
initial.commit586acc5fe2008-07-26 22:42:52102}
103
initial.commit586acc5fe2008-07-26 22:42:52104// We are expected to leak memory when simulating crashes.
[email protected]4d5e0362008-08-28 00:59:06105void DiskCacheTestWithCache::SimulateCrash() {
[email protected]398ad132013-04-02 15:11:01106 ASSERT_TRUE(!memory_only_);
[email protected]2a65aceb82011-12-19 20:59:27107 net::TestCompletionCallback cb;
108 int rv = cache_impl_->FlushQueueForTest(cb.callback());
robpercival214763f2016-07-01 23:27:01109 ASSERT_THAT(cb.GetResult(rv), IsOk());
initial.commit586acc5fe2008-07-26 22:42:52110 cache_impl_->ClearRefCountForTest();
111
[email protected]8c3f5a32013-08-01 11:57:53112 cache_.reset();
Maks Orlovichf3860652017-12-13 18:03:16113 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, size_, mask_));
initial.commit586acc5fe2008-07-26 22:42:52114
Maks Orlovich463dc502017-07-25 14:52:49115 CreateBackend(disk_cache::kNoRandom);
initial.commit586acc5fe2008-07-26 22:42:52116}
[email protected]a9da16d2008-07-30 21:41:54117
[email protected]4d5e0362008-08-28 00:59:06118void DiskCacheTestWithCache::SetTestMode() {
[email protected]398ad132013-04-02 15:11:01119 ASSERT_TRUE(!memory_only_);
[email protected]a9da16d2008-07-30 21:41:54120 cache_impl_->SetUnitTestMode();
121}
[email protected]bc4fb8e2010-03-18 23:58:17122
Ben Kelly5a16ed02018-09-07 21:28:09123void DiskCacheTestWithCache::SetMaxSize(int64_t size, bool should_succeed) {
[email protected]7aefb152011-01-21 23:46:49124 size_ = size;
[email protected]1ed95752013-04-23 00:12:36125 if (simple_cache_impl_)
Ben Kelly5a16ed02018-09-07 21:28:09126 EXPECT_EQ(should_succeed, simple_cache_impl_->SetMaxSize(size));
[email protected]1ed95752013-04-23 00:12:36127
[email protected]7aefb152011-01-21 23:46:49128 if (cache_impl_)
Ben Kelly5a16ed02018-09-07 21:28:09129 EXPECT_EQ(should_succeed, cache_impl_->SetMaxSize(size));
[email protected]7aefb152011-01-21 23:46:49130
131 if (mem_cache_)
Ben Kelly5a16ed02018-09-07 21:28:09132 EXPECT_EQ(should_succeed, mem_cache_->SetMaxSize(size));
[email protected]7aefb152011-01-21 23:46:49133}
134
Steven Bingler6afedf82019-01-08 19:34:49135int DiskCacheTestWithCache::OpenOrCreateEntry(const std::string& key,
136 disk_cache::Entry** entry) {
137 return OpenOrCreateEntryWithPriority(key, net::HIGHEST, entry);
138}
139
140int DiskCacheTestWithCache::OpenOrCreateEntryWithPriority(
141 const std::string& key,
142 net::RequestPriority request_priority,
143 disk_cache::Entry** entry) {
144 net::TestCompletionCallback cb;
145 int rv =
146 cache_->OpenOrCreateEntry(key, request_priority, entry, cb.callback());
147 return cb.GetResult(rv);
148}
149
[email protected]bc4fb8e2010-03-18 23:58:17150int DiskCacheTestWithCache::OpenEntry(const std::string& key,
151 disk_cache::Entry** entry) {
Josh Karlindd9a5d142018-06-06 00:35:48152 return OpenEntryWithPriority(key, net::HIGHEST, entry);
153}
154
155int DiskCacheTestWithCache::OpenEntryWithPriority(
156 const std::string& key,
157 net::RequestPriority request_priority,
158 disk_cache::Entry** entry) {
[email protected]2a65aceb82011-12-19 20:59:27159 net::TestCompletionCallback cb;
Josh Karlindd9a5d142018-06-06 00:35:48160 int rv = cache_->OpenEntry(key, request_priority, entry, cb.callback());
[email protected]bc4fb8e2010-03-18 23:58:17161 return cb.GetResult(rv);
162}
163
164int DiskCacheTestWithCache::CreateEntry(const std::string& key,
165 disk_cache::Entry** entry) {
Josh Karlindd9a5d142018-06-06 00:35:48166 return CreateEntryWithPriority(key, net::HIGHEST, entry);
167}
168
169int DiskCacheTestWithCache::CreateEntryWithPriority(
170 const std::string& key,
171 net::RequestPriority request_priority,
172 disk_cache::Entry** entry) {
[email protected]2a65aceb82011-12-19 20:59:27173 net::TestCompletionCallback cb;
Josh Karlindd9a5d142018-06-06 00:35:48174 int rv = cache_->CreateEntry(key, request_priority, entry, cb.callback());
[email protected]bc4fb8e2010-03-18 23:58:17175 return cb.GetResult(rv);
176}
177
178int DiskCacheTestWithCache::DoomEntry(const std::string& key) {
[email protected]42c459632011-12-17 02:20:23179 net::TestCompletionCallback cb;
Josh Karlindd9a5d142018-06-06 00:35:48180 int rv = cache_->DoomEntry(key, net::HIGHEST, cb.callback());
[email protected]bc4fb8e2010-03-18 23:58:17181 return cb.GetResult(rv);
182}
183
184int DiskCacheTestWithCache::DoomAllEntries() {
[email protected]6ad7c0912011-12-15 19:10:19185 net::TestCompletionCallback cb;
186 int rv = cache_->DoomAllEntries(cb.callback());
[email protected]bc4fb8e2010-03-18 23:58:17187 return cb.GetResult(rv);
188}
189
190int DiskCacheTestWithCache::DoomEntriesBetween(const base::Time initial_time,
191 const base::Time end_time) {
[email protected]6ad7c0912011-12-15 19:10:19192 net::TestCompletionCallback cb;
193 int rv = cache_->DoomEntriesBetween(initial_time, end_time, cb.callback());
[email protected]bc4fb8e2010-03-18 23:58:17194 return cb.GetResult(rv);
195}
196
197int DiskCacheTestWithCache::DoomEntriesSince(const base::Time initial_time) {
[email protected]2a65aceb82011-12-19 20:59:27198 net::TestCompletionCallback cb;
199 int rv = cache_->DoomEntriesSince(initial_time, cb.callback());
[email protected]bc4fb8e2010-03-18 23:58:17200 return cb.GetResult(rv);
201}
202
Ben Kelly5a16ed02018-09-07 21:28:09203int64_t DiskCacheTestWithCache::CalculateSizeOfAllEntries() {
204 net::TestInt64CompletionCallback cb;
205 int64_t rv = cache_->CalculateSizeOfAllEntries(cb.callback());
msramekaee01ceb2015-10-07 14:23:33206 return cb.GetResult(rv);
207}
208
Ben Kelly5a16ed02018-09-07 21:28:09209int64_t DiskCacheTestWithCache::CalculateSizeOfEntriesBetween(
dullwebera0030052017-01-16 11:56:04210 const base::Time initial_time,
211 const base::Time end_time) {
Ben Kelly5a16ed02018-09-07 21:28:09212 net::TestInt64CompletionCallback cb;
213 int64_t rv = cache_->CalculateSizeOfEntriesBetween(initial_time, end_time,
214 cb.callback());
dullwebera0030052017-01-16 11:56:04215 return cb.GetResult(rv);
216}
217
danakjd04b92d2016-04-16 01:16:49218std::unique_ptr<DiskCacheTestWithCache::TestIterator>
219DiskCacheTestWithCache::CreateIterator() {
220 return std::unique_ptr<TestIterator>(
221 new TestIterator(cache_->CreateIterator()));
[email protected]bc4fb8e2010-03-18 23:58:17222}
[email protected]fb2622f2010-07-13 18:00:56223
224void DiskCacheTestWithCache::FlushQueueForTest() {
225 if (memory_only_ || !cache_impl_)
226 return;
227
[email protected]2a65aceb82011-12-19 20:59:27228 net::TestCompletionCallback cb;
229 int rv = cache_impl_->FlushQueueForTest(cb.callback());
robpercival214763f2016-07-01 23:27:01230 EXPECT_THAT(cb.GetResult(rv), IsOk());
[email protected]fb2622f2010-07-13 18:00:56231}
[email protected]e1fcf142010-08-23 18:47:25232
[email protected]f27bbe002011-12-22 11:29:34233void DiskCacheTestWithCache::RunTaskForTest(const base::Closure& closure) {
[email protected]65188eb2010-09-16 20:59:29234 if (memory_only_ || !cache_impl_) {
[email protected]f27bbe002011-12-22 11:29:34235 closure.Run();
[email protected]65188eb2010-09-16 20:59:29236 return;
237 }
238
[email protected]2a65aceb82011-12-19 20:59:27239 net::TestCompletionCallback cb;
[email protected]f27bbe002011-12-22 11:29:34240 int rv = cache_impl_->RunTaskForTest(closure, cb.callback());
robpercival214763f2016-07-01 23:27:01241 EXPECT_THAT(cb.GetResult(rv), IsOk());
[email protected]65188eb2010-09-16 20:59:29242}
243
[email protected]e1fcf142010-08-23 18:47:25244int DiskCacheTestWithCache::ReadData(disk_cache::Entry* entry, int index,
245 int offset, net::IOBuffer* buf, int len) {
[email protected]2a65aceb82011-12-19 20:59:27246 net::TestCompletionCallback cb;
247 int rv = entry->ReadData(index, offset, buf, len, cb.callback());
[email protected]e1fcf142010-08-23 18:47:25248 return cb.GetResult(rv);
249}
250
[email protected]e1fcf142010-08-23 18:47:25251int DiskCacheTestWithCache::WriteData(disk_cache::Entry* entry, int index,
252 int offset, net::IOBuffer* buf, int len,
253 bool truncate) {
[email protected]2a65aceb82011-12-19 20:59:27254 net::TestCompletionCallback cb;
255 int rv = entry->WriteData(index, offset, buf, len, cb.callback(), truncate);
[email protected]e1fcf142010-08-23 18:47:25256 return cb.GetResult(rv);
257}
258
259int DiskCacheTestWithCache::ReadSparseData(disk_cache::Entry* entry,
Avi Drissman13fc8932015-12-20 04:40:46260 int64_t offset,
261 net::IOBuffer* buf,
[email protected]e1fcf142010-08-23 18:47:25262 int len) {
[email protected]2a65aceb82011-12-19 20:59:27263 net::TestCompletionCallback cb;
264 int rv = entry->ReadSparseData(offset, buf, len, cb.callback());
[email protected]e1fcf142010-08-23 18:47:25265 return cb.GetResult(rv);
266}
267
268int DiskCacheTestWithCache::WriteSparseData(disk_cache::Entry* entry,
Avi Drissman13fc8932015-12-20 04:40:46269 int64_t offset,
270 net::IOBuffer* buf,
271 int len) {
[email protected]2a65aceb82011-12-19 20:59:27272 net::TestCompletionCallback cb;
273 int rv = entry->WriteSparseData(offset, buf, len, cb.callback());
[email protected]e1fcf142010-08-23 18:47:25274 return cb.GetResult(rv);
275}
[email protected]7aefb152011-01-21 23:46:49276
[email protected]ceb61da32011-01-25 23:52:02277void DiskCacheTestWithCache::TrimForTest(bool empty) {
[email protected]f27bbe002011-12-22 11:29:34278 RunTaskForTest(base::Bind(&disk_cache::BackendImpl::TrimForTest,
279 base::Unretained(cache_impl_),
280 empty));
[email protected]ceb61da32011-01-25 23:52:02281}
282
283void DiskCacheTestWithCache::TrimDeletedListForTest(bool empty) {
[email protected]f27bbe002011-12-22 11:29:34284 RunTaskForTest(base::Bind(&disk_cache::BackendImpl::TrimDeletedListForTest,
285 base::Unretained(cache_impl_),
286 empty));
[email protected]ceb61da32011-01-25 23:52:02287}
288
[email protected]05f8087d2012-06-29 18:58:37289void DiskCacheTestWithCache::AddDelay() {
[email protected]8b2f8a52013-08-28 08:45:35290 if (simple_cache_mode_) {
291 // The simple cache uses second resolution for many timeouts, so it's safest
292 // to advance by at least whole seconds before falling back into the normal
293 // disk cache epsilon advance.
294 const base::Time initial_time = base::Time::Now();
295 do {
296 base::PlatformThread::YieldCurrentThread();
297 } while (base::Time::Now() -
298 initial_time < base::TimeDelta::FromSeconds(1));
299 }
300
[email protected]05f8087d2012-06-29 18:58:37301 base::Time initial = base::Time::Now();
302 while (base::Time::Now() <= initial) {
303 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1));
304 };
305}
306
[email protected]7aefb152011-01-21 23:46:49307void DiskCacheTestWithCache::TearDown() {
Bence Béky98447b12018-05-08 03:14:01308 RunUntilIdle();
[email protected]8c3f5a32013-08-01 11:57:53309 cache_.reset();
[email protected]7aefb152011-01-21 23:46:49310
[email protected]fccce902013-04-15 19:00:51311 if (!memory_only_ && !simple_cache_mode_ && integrity_) {
Maks Orlovichf3860652017-12-13 18:03:16312 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, size_, mask_));
[email protected]7aefb152011-01-21 23:46:49313 }
Bence Béky98447b12018-05-08 03:14:01314 RunUntilIdle();
Maks Orlovichf378b3a2017-10-31 16:27:30315 if (simple_cache_mode_ && simple_file_tracker_)
316 EXPECT_TRUE(simple_file_tracker_->IsEmptyForTesting());
317
[email protected]de677dc2013-09-13 02:12:25318 DiskCacheTest::TearDown();
[email protected]7aefb152011-01-21 23:46:49319}
320
321void DiskCacheTestWithCache::InitMemoryCache() {
[email protected]9eb8cdf2011-03-17 18:53:02322 mem_cache_ = new disk_cache::MemBackendImpl(NULL);
[email protected]8c3f5a32013-08-01 11:57:53323 cache_.reset(mem_cache_);
324 ASSERT_TRUE(cache_);
[email protected]7aefb152011-01-21 23:46:49325
326 if (size_)
327 EXPECT_TRUE(mem_cache_->SetMaxSize(size_));
328
329 ASSERT_TRUE(mem_cache_->Init());
330}
331
332void DiskCacheTestWithCache::InitDiskCache() {
[email protected]7aefb152011-01-21 23:46:49333 if (first_cleanup_)
[email protected]79b3fec2011-11-15 22:33:47334 ASSERT_TRUE(CleanupCacheDir());
[email protected]7aefb152011-01-21 23:46:49335
Maks Orlovich463dc502017-07-25 14:52:49336 CreateBackend(disk_cache::kNoRandom);
[email protected]398ad132013-04-02 15:11:01337}
[email protected]7aefb152011-01-21 23:46:49338
Maks Orlovich463dc502017-07-25 14:52:49339void DiskCacheTestWithCache::CreateBackend(uint32_t flags) {
[email protected]81e549a2014-08-21 04:19:55340 scoped_refptr<base::SingleThreadTaskRunner> runner;
[email protected]398ad132013-04-02 15:11:01341 if (use_current_thread_)
[email protected]81e549a2014-08-21 04:19:55342 runner = base::ThreadTaskRunnerHandle::Get();
[email protected]7aefb152011-01-21 23:46:49343 else
Maks Orlovich463dc502017-07-25 14:52:49344 runner = nullptr; // let the backend sort it out.
[email protected]7aefb152011-01-21 23:46:49345
[email protected]398ad132013-04-02 15:11:01346 if (simple_cache_mode_) {
Maks Orlovich922db0c2018-02-21 15:28:46347 DCHECK(!use_current_thread_)
348 << "Using current thread unsupported by SimpleCache";
[email protected]398ad132013-04-02 15:11:01349 net::TestCompletionCallback cb;
Maks Orlovichdb1f0922018-01-31 03:41:17350 // We limit ourselves to 64 fds since OS X by default gives us 256.
351 // (Chrome raises the number on startup, but the test fixture doesn't).
Maks Orlovichf378b3a2017-10-31 16:27:30352 if (!simple_file_tracker_)
Maks Orlovichdb1f0922018-01-31 03:41:17353 simple_file_tracker_ =
354 std::make_unique<disk_cache::SimpleFileTracker>(64);
Maks Orlovichf378b3a2017-10-31 16:27:30355 std::unique_ptr<disk_cache::SimpleBackendImpl> simple_backend =
356 std::make_unique<disk_cache::SimpleBackendImpl>(
357 cache_path_, /* cleanup_tracker = */ nullptr,
Maks Orlovich922db0c2018-02-21 15:28:46358 simple_file_tracker_.get(), size_, type_, /*net_log = */ nullptr);
[email protected]00831c822013-04-10 15:37:12359 int rv = simple_backend->Init(cb.callback());
robpercival214763f2016-07-01 23:27:01360 ASSERT_THAT(cb.GetResult(rv), IsOk());
[email protected]8c3f5a32013-08-01 11:57:53361 simple_cache_impl_ = simple_backend.get();
dchengc7eeda422015-12-26 03:56:48362 cache_ = std::move(simple_backend);
[email protected]7e48c1b2013-07-12 12:15:43363 if (simple_cache_wait_for_index_) {
364 net::TestCompletionCallback wait_for_index_cb;
[email protected]8c3f5a32013-08-01 11:57:53365 rv = simple_cache_impl_->index()->ExecuteWhenReady(
[email protected]7e48c1b2013-07-12 12:15:43366 wait_for_index_cb.callback());
robpercival214763f2016-07-01 23:27:01367 ASSERT_THAT(wait_for_index_cb.GetResult(rv), IsOk());
[email protected]7e48c1b2013-07-12 12:15:43368 }
[email protected]398ad132013-04-02 15:11:01369 return;
370 }
371
372 if (mask_)
Maks Orlovich036fd1f2017-08-07 17:51:11373 cache_impl_ = new disk_cache::BackendImpl(cache_path_, mask_, runner,
374 /* net_log = */ nullptr);
[email protected]398ad132013-04-02 15:11:01375 else
Maks Orlovich036fd1f2017-08-07 17:51:11376 cache_impl_ = new disk_cache::BackendImpl(cache_path_,
377 /* cleanup_tracker = */ nullptr,
378 runner, /* net_log = */ nullptr);
[email protected]8c3f5a32013-08-01 11:57:53379 cache_.reset(cache_impl_);
380 ASSERT_TRUE(cache_);
[email protected]7aefb152011-01-21 23:46:49381 if (size_)
382 EXPECT_TRUE(cache_impl_->SetMaxSize(size_));
[email protected]7aefb152011-01-21 23:46:49383 if (new_eviction_)
384 cache_impl_->SetNewEviction();
[email protected]7aefb152011-01-21 23:46:49385 cache_impl_->SetType(type_);
[email protected]398ad132013-04-02 15:11:01386 cache_impl_->SetFlags(flags);
[email protected]42c459632011-12-17 02:20:23387 net::TestCompletionCallback cb;
388 int rv = cache_impl_->Init(cb.callback());
robpercival214763f2016-07-01 23:27:01389 ASSERT_THAT(cb.GetResult(rv), IsOk());
[email protected]7aefb152011-01-21 23:46:49390}