Chromium Code Reviews| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 | 43 |
| 44 bool DiskCacheTest::CleanupCacheDir() { | 44 bool DiskCacheTest::CleanupCacheDir() { |
| 45 return DeleteCache(cache_path_); | 45 return DeleteCache(cache_path_); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void DiskCacheTest::TearDown() { | 48 void DiskCacheTest::TearDown() { |
| 49 base::RunLoop().RunUntilIdle(); | 49 base::RunLoop().RunUntilIdle(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 DiskCacheTestWithCache::DiskCacheTestWithCache() | 52 DiskCacheTestWithCache::DiskCacheTestWithCache() |
| 53 : cache_(NULL), | 53 : cache_impl_(NULL), |
| 54 cache_impl_(NULL), | |
| 55 simple_cache_impl_(NULL), | 54 simple_cache_impl_(NULL), |
| 56 mem_cache_(NULL), | 55 mem_cache_(NULL), |
| 57 mask_(0), | 56 mask_(0), |
| 58 size_(0), | 57 size_(0), |
| 59 type_(net::DISK_CACHE), | 58 type_(net::DISK_CACHE), |
| 60 memory_only_(false), | 59 memory_only_(false), |
| 61 simple_cache_mode_(false), | 60 simple_cache_mode_(false), |
| 62 simple_cache_wait_for_index_(true), | 61 simple_cache_wait_for_index_(true), |
| 63 force_creation_(false), | 62 force_creation_(false), |
| 64 new_eviction_(false), | 63 new_eviction_(false), |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 82 } | 81 } |
| 83 | 82 |
| 84 // We are expected to leak memory when simulating crashes. | 83 // We are expected to leak memory when simulating crashes. |
| 85 void DiskCacheTestWithCache::SimulateCrash() { | 84 void DiskCacheTestWithCache::SimulateCrash() { |
| 86 ASSERT_TRUE(!memory_only_); | 85 ASSERT_TRUE(!memory_only_); |
| 87 net::TestCompletionCallback cb; | 86 net::TestCompletionCallback cb; |
| 88 int rv = cache_impl_->FlushQueueForTest(cb.callback()); | 87 int rv = cache_impl_->FlushQueueForTest(cb.callback()); |
| 89 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 88 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 90 cache_impl_->ClearRefCountForTest(); | 89 cache_impl_->ClearRefCountForTest(); |
| 91 | 90 |
| 92 delete cache_impl_; | 91 cache_.reset(); |
| 93 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_)); | 92 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_)); |
| 94 | 93 |
| 95 CreateBackend(disk_cache::kNoRandom, &cache_thread_); | 94 CreateBackend(disk_cache::kNoRandom, &cache_thread_); |
| 96 } | 95 } |
| 97 | 96 |
| 98 void DiskCacheTestWithCache::SetTestMode() { | 97 void DiskCacheTestWithCache::SetTestMode() { |
| 99 ASSERT_TRUE(!memory_only_); | 98 ASSERT_TRUE(!memory_only_); |
| 100 cache_impl_->SetUnitTestMode(); | 99 cache_impl_->SetUnitTestMode(); |
| 101 } | 100 } |
| 102 | 101 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 | 222 |
| 224 void DiskCacheTestWithCache::AddDelay() { | 223 void DiskCacheTestWithCache::AddDelay() { |
| 225 base::Time initial = base::Time::Now(); | 224 base::Time initial = base::Time::Now(); |
| 226 while (base::Time::Now() <= initial) { | 225 while (base::Time::Now() <= initial) { |
| 227 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); | 226 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); |
| 228 }; | 227 }; |
| 229 } | 228 } |
| 230 | 229 |
| 231 void DiskCacheTestWithCache::TearDown() { | 230 void DiskCacheTestWithCache::TearDown() { |
| 232 base::RunLoop().RunUntilIdle(); | 231 base::RunLoop().RunUntilIdle(); |
| 233 delete cache_; | 232 cache_.reset(); |
| 234 if (cache_thread_.IsRunning()) | 233 if (cache_thread_.IsRunning()) |
| 235 cache_thread_.Stop(); | 234 cache_thread_.Stop(); |
| 236 | 235 |
| 237 if (!memory_only_ && !simple_cache_mode_ && integrity_) { | 236 if (!memory_only_ && !simple_cache_mode_ && integrity_) { |
| 238 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_)); | 237 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_)); |
| 239 } | 238 } |
| 240 | 239 |
| 241 PlatformTest::TearDown(); | 240 PlatformTest::TearDown(); |
| 242 } | 241 } |
| 243 | 242 |
| 244 void DiskCacheTestWithCache::InitMemoryCache() { | 243 void DiskCacheTestWithCache::InitMemoryCache() { |
| 245 mem_cache_ = new disk_cache::MemBackendImpl(NULL); | 244 mem_cache_ = new disk_cache::MemBackendImpl(NULL); |
| 246 cache_ = mem_cache_; | 245 cache_.reset(mem_cache_); |
| 247 ASSERT_TRUE(NULL != cache_); | 246 ASSERT_TRUE(NULL != cache_.get()); |
|
rvargas (doing something else)
2013/07/26 21:05:01
nit: (cache_.get())
qsr
2013/07/29 08:26:28
Done.
| |
| 248 | 247 |
| 249 if (size_) | 248 if (size_) |
| 250 EXPECT_TRUE(mem_cache_->SetMaxSize(size_)); | 249 EXPECT_TRUE(mem_cache_->SetMaxSize(size_)); |
| 251 | 250 |
| 252 ASSERT_TRUE(mem_cache_->Init()); | 251 ASSERT_TRUE(mem_cache_->Init()); |
| 253 } | 252 } |
| 254 | 253 |
| 255 void DiskCacheTestWithCache::InitDiskCache() { | 254 void DiskCacheTestWithCache::InitDiskCache() { |
| 256 if (first_cleanup_) | 255 if (first_cleanup_) |
| 257 ASSERT_TRUE(CleanupCacheDir()); | 256 ASSERT_TRUE(CleanupCacheDir()); |
| 258 | 257 |
| 259 if (!cache_thread_.IsRunning()) { | 258 if (!cache_thread_.IsRunning()) { |
| 260 ASSERT_TRUE(cache_thread_.StartWithOptions( | 259 ASSERT_TRUE(cache_thread_.StartWithOptions( |
| 261 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 260 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 262 } | 261 } |
| 263 ASSERT_TRUE(cache_thread_.message_loop() != NULL); | 262 ASSERT_TRUE(cache_thread_.message_loop() != NULL); |
| 264 | 263 |
| 265 CreateBackend(disk_cache::kNoRandom, &cache_thread_); | 264 CreateBackend(disk_cache::kNoRandom, &cache_thread_); |
| 266 } | 265 } |
| 267 | 266 |
| 268 void DiskCacheTestWithCache::CreateBackend(uint32 flags, base::Thread* thread) { | 267 void DiskCacheTestWithCache::CreateBackend(uint32 flags, base::Thread* thread) { |
| 269 base::MessageLoopProxy* runner; | 268 base::MessageLoopProxy* runner; |
| 270 if (use_current_thread_) | 269 if (use_current_thread_) |
| 271 runner = base::MessageLoopProxy::current().get(); | 270 runner = base::MessageLoopProxy::current().get(); |
| 272 else | 271 else |
| 273 runner = thread->message_loop_proxy().get(); | 272 runner = thread->message_loop_proxy().get(); |
| 274 | 273 |
| 275 if (simple_cache_mode_) { | 274 if (simple_cache_mode_) { |
| 276 net::TestCompletionCallback cb; | 275 net::TestCompletionCallback cb; |
| 277 disk_cache::SimpleBackendImpl* simple_backend = | 276 scoped_ptr<disk_cache::SimpleBackendImpl> simple_backend( |
| 278 new disk_cache::SimpleBackendImpl( | 277 new disk_cache::SimpleBackendImpl( |
| 279 cache_path_, size_, type_, make_scoped_refptr(runner).get(), NULL); | 278 cache_path_, size_, type_, make_scoped_refptr(runner).get(), NULL)); |
| 280 int rv = simple_backend->Init(cb.callback()); | 279 int rv = simple_backend->Init(cb.callback()); |
| 281 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 280 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 282 cache_ = simple_cache_impl_ = simple_backend; | 281 simple_cache_impl_ = simple_backend.get(); |
| 282 cache_ = simple_backend.PassAs<disk_cache::Backend>(); | |
| 283 if (simple_cache_wait_for_index_) { | 283 if (simple_cache_wait_for_index_) { |
| 284 net::TestCompletionCallback wait_for_index_cb; | 284 net::TestCompletionCallback wait_for_index_cb; |
| 285 rv = simple_backend->index()->ExecuteWhenReady( | 285 rv = simple_cache_impl_->index()->ExecuteWhenReady( |
| 286 wait_for_index_cb.callback()); | 286 wait_for_index_cb.callback()); |
| 287 ASSERT_EQ(net::OK, wait_for_index_cb.GetResult(rv)); | 287 ASSERT_EQ(net::OK, wait_for_index_cb.GetResult(rv)); |
| 288 } | 288 } |
| 289 return; | 289 return; |
| 290 } | 290 } |
| 291 | 291 |
| 292 if (mask_) | 292 if (mask_) |
| 293 cache_impl_ = new disk_cache::BackendImpl(cache_path_, mask_, runner, NULL); | 293 cache_impl_ = new disk_cache::BackendImpl(cache_path_, mask_, runner, NULL); |
| 294 else | 294 else |
| 295 cache_impl_ = new disk_cache::BackendImpl(cache_path_, runner, NULL); | 295 cache_impl_ = new disk_cache::BackendImpl(cache_path_, runner, NULL); |
| 296 cache_ = cache_impl_; | 296 cache_.reset(cache_impl_); |
| 297 ASSERT_TRUE(NULL != cache_); | 297 ASSERT_TRUE(NULL != cache_.get()); |
|
rvargas (doing something else)
2013/07/26 21:05:01
ditto
qsr
2013/07/29 08:26:28
Done.
| |
| 298 if (size_) | 298 if (size_) |
| 299 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); | 299 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); |
| 300 if (new_eviction_) | 300 if (new_eviction_) |
| 301 cache_impl_->SetNewEviction(); | 301 cache_impl_->SetNewEviction(); |
| 302 cache_impl_->SetType(type_); | 302 cache_impl_->SetType(type_); |
| 303 cache_impl_->SetFlags(flags); | 303 cache_impl_->SetFlags(flags); |
| 304 net::TestCompletionCallback cb; | 304 net::TestCompletionCallback cb; |
| 305 int rv = cache_impl_->Init(cb.callback()); | 305 int rv = cache_impl_->Init(cb.callback()); |
| 306 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 306 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 307 cache_ = cache_impl_; | |
| 308 } | 307 } |
| OLD | NEW |