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