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/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
11 #include "net/base/test_completion_callback.h" | 11 #include "net/base/test_completion_callback.h" |
12 #include "net/disk_cache/backend_impl.h" | 12 #include "net/disk_cache/backend_impl.h" |
| 13 #include "net/disk_cache/disk_cache.h" |
13 #include "net/disk_cache/disk_cache_test_util.h" | 14 #include "net/disk_cache/disk_cache_test_util.h" |
14 #include "net/disk_cache/mem_backend_impl.h" | 15 #include "net/disk_cache/mem_backend_impl.h" |
15 | 16 |
16 DiskCacheTest::DiskCacheTest() { | 17 DiskCacheTest::DiskCacheTest() { |
17 CHECK(temp_dir_.CreateUniqueTempDir()); | 18 CHECK(temp_dir_.CreateUniqueTempDir()); |
18 cache_path_ = temp_dir_.path(); | 19 cache_path_ = temp_dir_.path(); |
19 if (!MessageLoop::current()) | 20 if (!MessageLoop::current()) |
20 message_loop_.reset(new MessageLoopForIO()); | 21 message_loop_.reset(new MessageLoopForIO()); |
21 } | 22 } |
22 | 23 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 use_current_thread_(false), | 61 use_current_thread_(false), |
61 cache_thread_("CacheThread") { | 62 cache_thread_("CacheThread") { |
62 } | 63 } |
63 | 64 |
64 DiskCacheTestWithCache::~DiskCacheTestWithCache() {} | 65 DiskCacheTestWithCache::~DiskCacheTestWithCache() {} |
65 | 66 |
66 void DiskCacheTestWithCache::InitCache() { | 67 void DiskCacheTestWithCache::InitCache() { |
67 if (mask_ || new_eviction_) | 68 if (mask_ || new_eviction_) |
68 implementation_ = true; | 69 implementation_ = true; |
69 | 70 |
| 71 // TODO(pasko,gavinp): run tests with Simple Cache as well. |
70 if (memory_only_) | 72 if (memory_only_) |
71 InitMemoryCache(); | 73 InitMemoryCache(); |
72 else | 74 else |
73 InitDiskCache(); | 75 InitDiskCache(); |
74 | 76 |
75 ASSERT_TRUE(NULL != cache_); | 77 ASSERT_TRUE(NULL != cache_); |
76 if (first_cleanup_) | 78 if (first_cleanup_) |
77 ASSERT_EQ(0, cache_->GetEntryCount()); | 79 ASSERT_EQ(0, cache_->GetEntryCount()); |
78 } | 80 } |
79 | 81 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 ASSERT_TRUE(cache_thread_.message_loop() != NULL); | 263 ASSERT_TRUE(cache_thread_.message_loop() != NULL); |
262 | 264 |
263 if (implementation_) | 265 if (implementation_) |
264 return InitDiskCacheImpl(); | 266 return InitDiskCacheImpl(); |
265 | 267 |
266 scoped_refptr<base::MessageLoopProxy> thread = | 268 scoped_refptr<base::MessageLoopProxy> thread = |
267 use_current_thread_ ? base::MessageLoopProxy::current() : | 269 use_current_thread_ ? base::MessageLoopProxy::current() : |
268 cache_thread_.message_loop_proxy(); | 270 cache_thread_.message_loop_proxy(); |
269 | 271 |
270 net::TestCompletionCallback cb; | 272 net::TestCompletionCallback cb; |
271 int rv = disk_cache::BackendImpl::CreateBackend( | 273 int rv = disk_cache::CreateCacheBackendWithFlags(type_, cache_path_, size_, |
272 cache_path_, force_creation_, size_, type_, | 274 force_creation_, disk_cache::kNoRandom, thread, NULL, &cache_, |
273 disk_cache::kNoRandom, thread, NULL, &cache_, cb.callback()); | 275 cb.callback()); |
| 276 |
274 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 277 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
275 } | 278 } |
276 | 279 |
277 void DiskCacheTestWithCache::InitDiskCacheImpl() { | 280 void DiskCacheTestWithCache::InitDiskCacheImpl() { |
278 scoped_refptr<base::MessageLoopProxy> thread = | 281 scoped_refptr<base::MessageLoopProxy> thread = |
279 use_current_thread_ ? base::MessageLoopProxy::current() : | 282 use_current_thread_ ? base::MessageLoopProxy::current() : |
280 cache_thread_.message_loop_proxy(); | 283 cache_thread_.message_loop_proxy(); |
281 if (mask_) | 284 if (mask_) |
282 cache_impl_ = new disk_cache::BackendImpl(cache_path_, mask_, thread, NULL); | 285 cache_impl_ = new disk_cache::BackendImpl(cache_path_, mask_, thread, NULL); |
283 else | 286 else |
284 cache_impl_ = new disk_cache::BackendImpl(cache_path_, thread, NULL); | 287 cache_impl_ = new disk_cache::BackendImpl(cache_path_, thread, NULL); |
285 | 288 |
286 cache_ = cache_impl_; | 289 cache_ = cache_impl_; |
287 ASSERT_TRUE(NULL != cache_); | 290 ASSERT_TRUE(NULL != cache_); |
288 | 291 |
289 if (size_) | 292 if (size_) |
290 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); | 293 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); |
291 | 294 |
292 if (new_eviction_) | 295 if (new_eviction_) |
293 cache_impl_->SetNewEviction(); | 296 cache_impl_->SetNewEviction(); |
294 | 297 |
295 cache_impl_->SetType(type_); | 298 cache_impl_->SetType(type_); |
296 cache_impl_->SetFlags(disk_cache::kNoRandom); | 299 cache_impl_->SetFlags(disk_cache::kNoRandom); |
297 net::TestCompletionCallback cb; | 300 net::TestCompletionCallback cb; |
298 int rv = cache_impl_->Init(cb.callback()); | 301 int rv = cache_impl_->Init(cb.callback()); |
299 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 302 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
300 } | 303 } |
OLD | NEW |