| OLD | NEW |
| 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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 "net/base/io_buffer.h" | 7 #include "net/base/io_buffer.h" |
| 8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
| 9 #include "net/base/test_completion_callback.h" | 9 #include "net/base/test_completion_callback.h" |
| 10 #include "net/disk_cache/backend_impl.h" | 10 #include "net/disk_cache/backend_impl.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 cache_ = mem_cache_; | 48 cache_ = mem_cache_; |
| 49 ASSERT_TRUE(NULL != cache_); | 49 ASSERT_TRUE(NULL != cache_); |
| 50 | 50 |
| 51 if (size_) | 51 if (size_) |
| 52 EXPECT_TRUE(mem_cache_->SetMaxSize(size_)); | 52 EXPECT_TRUE(mem_cache_->SetMaxSize(size_)); |
| 53 | 53 |
| 54 ASSERT_TRUE(mem_cache_->Init()); | 54 ASSERT_TRUE(mem_cache_->Init()); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void DiskCacheTestWithCache::InitDiskCache() { | 57 void DiskCacheTestWithCache::InitDiskCache() { |
| 58 FilePath path = GetCacheFilePath(); |
| 58 if (first_cleanup_) | 59 if (first_cleanup_) |
| 59 ASSERT_TRUE(DeleteCache(test_cache_.path())); | 60 ASSERT_TRUE(DeleteCache(path)); |
| 60 | 61 |
| 61 if (!cache_thread_.IsRunning()) { | 62 if (!cache_thread_.IsRunning()) { |
| 62 EXPECT_TRUE(cache_thread_.StartWithOptions( | 63 EXPECT_TRUE(cache_thread_.StartWithOptions( |
| 63 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 64 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
| 64 } | 65 } |
| 65 ASSERT_TRUE(cache_thread_.message_loop() != NULL); | 66 ASSERT_TRUE(cache_thread_.message_loop() != NULL); |
| 66 | 67 |
| 67 if (implementation_) | 68 if (implementation_) |
| 68 return InitDiskCacheImpl(test_cache_.path()); | 69 return InitDiskCacheImpl(path); |
| 69 | 70 |
| 70 scoped_refptr<base::MessageLoopProxy> thread = | 71 scoped_refptr<base::MessageLoopProxy> thread = |
| 71 use_current_thread_ ? base::MessageLoopProxy::CreateForCurrentThread() : | 72 use_current_thread_ ? base::MessageLoopProxy::CreateForCurrentThread() : |
| 72 cache_thread_.message_loop_proxy(); | 73 cache_thread_.message_loop_proxy(); |
| 73 | 74 |
| 74 TestCompletionCallback cb; | 75 TestCompletionCallback cb; |
| 75 int rv = disk_cache::BackendImpl::CreateBackend( | 76 int rv = disk_cache::BackendImpl::CreateBackend( |
| 76 test_cache_.path(), force_creation_, size_, type_, | 77 path, force_creation_, size_, type_, |
| 77 disk_cache::kNoRandom, thread, &cache_, &cb); | 78 disk_cache::kNoRandom, thread, &cache_, &cb); |
| 78 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 79 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 79 } | 80 } |
| 80 | 81 |
| 81 void DiskCacheTestWithCache::InitDiskCacheImpl(const FilePath& path) { | 82 void DiskCacheTestWithCache::InitDiskCacheImpl(const FilePath& path) { |
| 82 scoped_refptr<base::MessageLoopProxy> thread = | 83 scoped_refptr<base::MessageLoopProxy> thread = |
| 83 use_current_thread_ ? base::MessageLoopProxy::CreateForCurrentThread() : | 84 use_current_thread_ ? base::MessageLoopProxy::CreateForCurrentThread() : |
| 84 cache_thread_.message_loop_proxy(); | 85 cache_thread_.message_loop_proxy(); |
| 85 if (mask_) | 86 if (mask_) |
| 86 cache_impl_ = new disk_cache::BackendImpl(path, mask_, thread); | 87 cache_impl_ = new disk_cache::BackendImpl(path, mask_, thread); |
| 87 else | 88 else |
| (...skipping 15 matching lines...) Expand all Loading... |
| 103 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 104 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 104 } | 105 } |
| 105 | 106 |
| 106 void DiskCacheTestWithCache::TearDown() { | 107 void DiskCacheTestWithCache::TearDown() { |
| 107 MessageLoop::current()->RunAllPending(); | 108 MessageLoop::current()->RunAllPending(); |
| 108 delete cache_; | 109 delete cache_; |
| 109 if (cache_thread_.IsRunning()) | 110 if (cache_thread_.IsRunning()) |
| 110 cache_thread_.Stop(); | 111 cache_thread_.Stop(); |
| 111 | 112 |
| 112 if (!memory_only_ && integrity_) { | 113 if (!memory_only_ && integrity_) { |
| 113 EXPECT_TRUE(CheckCacheIntegrity(path(), new_eviction_)); | 114 FilePath path = GetCacheFilePath(); |
| 115 EXPECT_TRUE(CheckCacheIntegrity(path, new_eviction_)); |
| 114 } | 116 } |
| 115 | 117 |
| 116 PlatformTest::TearDown(); | 118 PlatformTest::TearDown(); |
| 117 } | 119 } |
| 118 | 120 |
| 119 // We are expected to leak memory when simulating crashes. | 121 // We are expected to leak memory when simulating crashes. |
| 120 void DiskCacheTestWithCache::SimulateCrash() { | 122 void DiskCacheTestWithCache::SimulateCrash() { |
| 121 ASSERT_TRUE(implementation_ && !memory_only_); | 123 ASSERT_TRUE(implementation_ && !memory_only_); |
| 122 TestCompletionCallback cb; | 124 TestCompletionCallback cb; |
| 123 int rv = cache_impl_->FlushQueueForTest(&cb); | 125 int rv = cache_impl_->FlushQueueForTest(&cb); |
| 124 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 126 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 125 cache_impl_->ClearRefCountForTest(); | 127 cache_impl_->ClearRefCountForTest(); |
| 126 | 128 |
| 127 delete cache_impl_; | 129 delete cache_impl_; |
| 128 EXPECT_TRUE(CheckCacheIntegrity(path(), new_eviction_)); | 130 FilePath path = GetCacheFilePath(); |
| 131 EXPECT_TRUE(CheckCacheIntegrity(path, new_eviction_)); |
| 129 | 132 |
| 130 InitDiskCacheImpl(path()); | 133 InitDiskCacheImpl(path); |
| 131 } | 134 } |
| 132 | 135 |
| 133 void DiskCacheTestWithCache::SetTestMode() { | 136 void DiskCacheTestWithCache::SetTestMode() { |
| 134 ASSERT_TRUE(implementation_ && !memory_only_); | 137 ASSERT_TRUE(implementation_ && !memory_only_); |
| 135 cache_impl_->SetUnitTestMode(); | 138 cache_impl_->SetUnitTestMode(); |
| 136 } | 139 } |
| 137 | 140 |
| 138 int DiskCacheTestWithCache::OpenEntry(const std::string& key, | 141 int DiskCacheTestWithCache::OpenEntry(const std::string& key, |
| 139 disk_cache::Entry** entry) { | 142 disk_cache::Entry** entry) { |
| 140 TestCompletionCallback cb; | 143 TestCompletionCallback cb; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 return cb.GetResult(rv); | 229 return cb.GetResult(rv); |
| 227 } | 230 } |
| 228 | 231 |
| 229 int DiskCacheTestWithCache::WriteSparseData(disk_cache::Entry* entry, | 232 int DiskCacheTestWithCache::WriteSparseData(disk_cache::Entry* entry, |
| 230 int64 offset, | 233 int64 offset, |
| 231 net::IOBuffer* buf, int len) { | 234 net::IOBuffer* buf, int len) { |
| 232 TestCompletionCallback cb; | 235 TestCompletionCallback cb; |
| 233 int rv = entry->WriteSparseData(offset, buf, len, &cb); | 236 int rv = entry->WriteSparseData(offset, buf, len, &cb); |
| 234 return cb.GetResult(rv); | 237 return cb.GetResult(rv); |
| 235 } | 238 } |
| OLD | NEW |