OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/disk_cache/disk_cache_test_base.h" | 5 #include "net/disk_cache/disk_cache_test_base.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 } | 45 } |
46 | 46 |
47 bool DiskCacheTest::CleanupCacheDir() { | 47 bool DiskCacheTest::CleanupCacheDir() { |
48 return DeleteCache(cache_path_); | 48 return DeleteCache(cache_path_); |
49 } | 49 } |
50 | 50 |
51 void DiskCacheTest::TearDown() { | 51 void DiskCacheTest::TearDown() { |
52 base::RunLoop().RunUntilIdle(); | 52 base::RunLoop().RunUntilIdle(); |
53 } | 53 } |
54 | 54 |
| 55 DiskCacheTestWithCache::TestIterator::TestIterator( |
| 56 scoped_ptr<disk_cache::Backend::Iterator> iterator) |
| 57 : iterator_(iterator.Pass()) { |
| 58 } |
| 59 |
| 60 DiskCacheTestWithCache::TestIterator::~TestIterator() {} |
| 61 |
| 62 int DiskCacheTestWithCache::TestIterator::OpenNextEntry( |
| 63 disk_cache::Entry** next_entry) { |
| 64 net::TestCompletionCallback cb; |
| 65 int rv = iterator_->OpenNextEntry(next_entry, cb.callback()); |
| 66 return cb.GetResult(rv); |
| 67 } |
| 68 |
55 DiskCacheTestWithCache::DiskCacheTestWithCache() | 69 DiskCacheTestWithCache::DiskCacheTestWithCache() |
56 : cache_impl_(NULL), | 70 : cache_impl_(NULL), |
57 simple_cache_impl_(NULL), | 71 simple_cache_impl_(NULL), |
58 mem_cache_(NULL), | 72 mem_cache_(NULL), |
59 mask_(0), | 73 mask_(0), |
60 size_(0), | 74 size_(0), |
61 type_(net::DISK_CACHE), | 75 type_(net::DISK_CACHE), |
62 memory_only_(false), | 76 memory_only_(false), |
63 simple_cache_mode_(false), | 77 simple_cache_mode_(false), |
64 simple_cache_wait_for_index_(true), | 78 simple_cache_wait_for_index_(true), |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 int rv = cache_->DoomEntriesBetween(initial_time, end_time, cb.callback()); | 160 int rv = cache_->DoomEntriesBetween(initial_time, end_time, cb.callback()); |
147 return cb.GetResult(rv); | 161 return cb.GetResult(rv); |
148 } | 162 } |
149 | 163 |
150 int DiskCacheTestWithCache::DoomEntriesSince(const base::Time initial_time) { | 164 int DiskCacheTestWithCache::DoomEntriesSince(const base::Time initial_time) { |
151 net::TestCompletionCallback cb; | 165 net::TestCompletionCallback cb; |
152 int rv = cache_->DoomEntriesSince(initial_time, cb.callback()); | 166 int rv = cache_->DoomEntriesSince(initial_time, cb.callback()); |
153 return cb.GetResult(rv); | 167 return cb.GetResult(rv); |
154 } | 168 } |
155 | 169 |
156 int DiskCacheTestWithCache::OpenNextEntry(void** iter, | 170 scoped_ptr<DiskCacheTestWithCache::TestIterator> |
157 disk_cache::Entry** next_entry) { | 171 DiskCacheTestWithCache::CreateIterator() { |
158 net::TestCompletionCallback cb; | 172 return scoped_ptr<TestIterator>(new TestIterator(cache_->CreateIterator())); |
159 int rv = cache_->OpenNextEntry(iter, next_entry, cb.callback()); | |
160 return cb.GetResult(rv); | |
161 } | 173 } |
162 | 174 |
163 void DiskCacheTestWithCache::FlushQueueForTest() { | 175 void DiskCacheTestWithCache::FlushQueueForTest() { |
164 if (memory_only_ || !cache_impl_) | 176 if (memory_only_ || !cache_impl_) |
165 return; | 177 return; |
166 | 178 |
167 net::TestCompletionCallback cb; | 179 net::TestCompletionCallback cb; |
168 int rv = cache_impl_->FlushQueueForTest(cb.callback()); | 180 int rv = cache_impl_->FlushQueueForTest(cb.callback()); |
169 EXPECT_EQ(net::OK, cb.GetResult(rv)); | 181 EXPECT_EQ(net::OK, cb.GetResult(rv)); |
170 } | 182 } |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 if (size_) | 327 if (size_) |
316 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); | 328 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); |
317 if (new_eviction_) | 329 if (new_eviction_) |
318 cache_impl_->SetNewEviction(); | 330 cache_impl_->SetNewEviction(); |
319 cache_impl_->SetType(type_); | 331 cache_impl_->SetType(type_); |
320 cache_impl_->SetFlags(flags); | 332 cache_impl_->SetFlags(flags); |
321 net::TestCompletionCallback cb; | 333 net::TestCompletionCallback cb; |
322 int rv = cache_impl_->Init(cb.callback()); | 334 int rv = cache_impl_->Init(cb.callback()); |
323 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 335 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
324 } | 336 } |
OLD | NEW |