| 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 "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 | 252 |
| 253 if (!cache_thread_.IsRunning()) { | 253 if (!cache_thread_.IsRunning()) { |
| 254 ASSERT_TRUE(cache_thread_.StartWithOptions( | 254 ASSERT_TRUE(cache_thread_.StartWithOptions( |
| 255 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 255 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
| 256 } | 256 } |
| 257 ASSERT_TRUE(cache_thread_.message_loop() != NULL); | 257 ASSERT_TRUE(cache_thread_.message_loop() != NULL); |
| 258 | 258 |
| 259 CreateBackend(disk_cache::kNoRandom, &cache_thread_); | 259 CreateBackend(disk_cache::kNoRandom, &cache_thread_); |
| 260 } | 260 } |
| 261 | 261 |
| 262 // Testing backend creation retry logic is hard because the CacheCreator and | |
| 263 // cache backend(s) are tightly coupled. So we take the default backend often. | |
| 264 // Tests themselves need to be adjusted for platforms where the BackendImpl is | |
| 265 // not the default backend. | |
| 266 void DiskCacheTestWithCache::InitDefaultCacheViaCreator() { | |
| 267 if (!cache_thread_.IsRunning()) { | |
| 268 ASSERT_TRUE(cache_thread_.StartWithOptions( | |
| 269 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | |
| 270 } | |
| 271 ASSERT_TRUE(cache_thread_.message_loop() != NULL); | |
| 272 | |
| 273 net::TestCompletionCallback cb; | |
| 274 disk_cache::CacheCreator* creator = new disk_cache::CacheCreator( | |
| 275 cache_path_, true, 0, net::DISK_CACHE, disk_cache::kNoRandom, | |
| 276 cache_thread_.message_loop_proxy(), NULL, &cache_, cb.callback()); | |
| 277 int rv = creator->Run(); | |
| 278 ASSERT_EQ(net::OK, cb.GetResult(rv)); | |
| 279 } | |
| 280 | |
| 281 void DiskCacheTestWithCache::CreateBackend(uint32 flags, base::Thread* thread) { | 262 void DiskCacheTestWithCache::CreateBackend(uint32 flags, base::Thread* thread) { |
| 282 base::MessageLoopProxy* runner; | 263 base::MessageLoopProxy* runner; |
| 283 if (use_current_thread_) | 264 if (use_current_thread_) |
| 284 runner = base::MessageLoopProxy::current(); | 265 runner = base::MessageLoopProxy::current(); |
| 285 else | 266 else |
| 286 runner = thread->message_loop_proxy(); | 267 runner = thread->message_loop_proxy(); |
| 287 | 268 |
| 288 if (simple_cache_mode_) { | 269 if (simple_cache_mode_) { |
| 289 net::TestCompletionCallback cb; | 270 net::TestCompletionCallback cb; |
| 290 disk_cache::Backend* simple_backend; | 271 disk_cache::Backend* simple_backend; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 307 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); | 288 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); |
| 308 if (new_eviction_) | 289 if (new_eviction_) |
| 309 cache_impl_->SetNewEviction(); | 290 cache_impl_->SetNewEviction(); |
| 310 cache_impl_->SetType(type_); | 291 cache_impl_->SetType(type_); |
| 311 cache_impl_->SetFlags(flags); | 292 cache_impl_->SetFlags(flags); |
| 312 net::TestCompletionCallback cb; | 293 net::TestCompletionCallback cb; |
| 313 int rv = cache_impl_->Init(cb.callback()); | 294 int rv = cache_impl_->Init(cb.callback()); |
| 314 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 295 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 315 cache_ = cache_impl_; | 296 cache_ = cache_impl_; |
| 316 } | 297 } |
| OLD | NEW |