| 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 | 262 void DiskCacheTestWithCache::CreateCacheViaPublicInterface() { |
| 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()) { | 263 if (!cache_thread_.IsRunning()) { |
| 268 ASSERT_TRUE(cache_thread_.StartWithOptions( | 264 ASSERT_TRUE(cache_thread_.StartWithOptions( |
| 269 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 265 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
| 270 } | 266 } |
| 271 ASSERT_TRUE(cache_thread_.message_loop() != NULL); | 267 ASSERT_TRUE(cache_thread_.message_loop() != NULL); |
| 272 | 268 |
| 273 net::TestCompletionCallback cb; | 269 net::TestCompletionCallback cb; |
| 274 disk_cache::CacheCreator* creator = new disk_cache::CacheCreator( | 270 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, cache_path_, 0, true, |
| 275 cache_path_, true, 0, net::DISK_CACHE, disk_cache::kNoRandom, | 271 cache_thread_.message_loop_proxy(), |
| 276 cache_thread_.message_loop_proxy(), NULL, &cache_, cb.callback()); | 272 NULL, &cache_, cb.callback()); |
| 277 int rv = creator->Run(); | |
| 278 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 273 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 279 } | 274 } |
| 280 | 275 |
| 281 void DiskCacheTestWithCache::CreateBackend(uint32 flags, base::Thread* thread) { | 276 void DiskCacheTestWithCache::CreateBackend(uint32 flags, base::Thread* thread) { |
| 282 base::MessageLoopProxy* runner; | 277 base::MessageLoopProxy* runner; |
| 283 if (use_current_thread_) | 278 if (use_current_thread_) |
| 284 runner = base::MessageLoopProxy::current(); | 279 runner = base::MessageLoopProxy::current(); |
| 285 else | 280 else |
| 286 runner = thread->message_loop_proxy(); | 281 runner = thread->message_loop_proxy(); |
| 287 | 282 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 307 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); | 302 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); |
| 308 if (new_eviction_) | 303 if (new_eviction_) |
| 309 cache_impl_->SetNewEviction(); | 304 cache_impl_->SetNewEviction(); |
| 310 cache_impl_->SetType(type_); | 305 cache_impl_->SetType(type_); |
| 311 cache_impl_->SetFlags(flags); | 306 cache_impl_->SetFlags(flags); |
| 312 net::TestCompletionCallback cb; | 307 net::TestCompletionCallback cb; |
| 313 int rv = cache_impl_->Init(cb.callback()); | 308 int rv = cache_impl_->Init(cb.callback()); |
| 314 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 309 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 315 cache_ = cache_impl_; | 310 cache_ = cache_impl_; |
| 316 } | 311 } |
| OLD | NEW |