| 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/net_errors.h" | |
| 8 #include "net/base/test_completion_callback.h" | 7 #include "net/base/test_completion_callback.h" |
| 9 #include "net/disk_cache/backend_impl.h" | 8 #include "net/disk_cache/backend_impl.h" |
| 10 #include "net/disk_cache/disk_cache_test_util.h" | 9 #include "net/disk_cache/disk_cache_test_util.h" |
| 11 #include "net/disk_cache/mem_backend_impl.h" | 10 #include "net/disk_cache/mem_backend_impl.h" |
| 12 | 11 |
| 13 void DiskCacheTest::TearDown() { | 12 void DiskCacheTest::TearDown() { |
| 14 MessageLoop::current()->RunAllPending(); | 13 MessageLoop::current()->RunAllPending(); |
| 15 } | 14 } |
| 16 | 15 |
| 17 void DiskCacheTestWithCache::SetMaxSize(int size) { | 16 void DiskCacheTestWithCache::SetMaxSize(int size) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 59 |
| 61 if (!cache_thread_.IsRunning()) { | 60 if (!cache_thread_.IsRunning()) { |
| 62 EXPECT_TRUE(cache_thread_.StartWithOptions( | 61 EXPECT_TRUE(cache_thread_.StartWithOptions( |
| 63 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 62 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
| 64 } | 63 } |
| 65 ASSERT_TRUE(cache_thread_.message_loop() != NULL); | 64 ASSERT_TRUE(cache_thread_.message_loop() != NULL); |
| 66 | 65 |
| 67 if (implementation_) | 66 if (implementation_) |
| 68 return InitDiskCacheImpl(path); | 67 return InitDiskCacheImpl(path); |
| 69 | 68 |
| 70 scoped_refptr<base::MessageLoopProxy> thread = | |
| 71 use_current_thread_ ? base::MessageLoopProxy::CreateForCurrentThread() : | |
| 72 cache_thread_.message_loop_proxy(); | |
| 73 | |
| 74 TestCompletionCallback cb; | 69 TestCompletionCallback cb; |
| 75 int rv = disk_cache::BackendImpl::CreateBackend( | 70 int rv = disk_cache::BackendImpl::CreateBackend( |
| 76 path, force_creation_, size_, net::DISK_CACHE, | 71 path, force_creation_, size_, net::DISK_CACHE, |
| 77 disk_cache::kNoRandom, thread, &cache_, &cb); | 72 disk_cache::kNoRandom, cache_thread_.message_loop_proxy(), |
| 73 &cache_, &cb); |
| 78 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 74 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 79 } | 75 } |
| 80 | 76 |
| 81 void DiskCacheTestWithCache::InitDiskCacheImpl(const FilePath& path) { | 77 void DiskCacheTestWithCache::InitDiskCacheImpl(const FilePath& path) { |
| 82 scoped_refptr<base::MessageLoopProxy> thread = | |
| 83 use_current_thread_ ? base::MessageLoopProxy::CreateForCurrentThread() : | |
| 84 cache_thread_.message_loop_proxy(); | |
| 85 if (mask_) | 78 if (mask_) |
| 86 cache_impl_ = new disk_cache::BackendImpl(path, mask_, thread); | 79 cache_impl_ = new disk_cache::BackendImpl( |
| 80 path, mask_, cache_thread_.message_loop_proxy()); |
| 87 else | 81 else |
| 88 cache_impl_ = new disk_cache::BackendImpl(path, thread); | 82 cache_impl_ = new disk_cache::BackendImpl( |
| 83 path, cache_thread_.message_loop_proxy()); |
| 89 | 84 |
| 90 cache_ = cache_impl_; | 85 cache_ = cache_impl_; |
| 91 ASSERT_TRUE(NULL != cache_); | 86 ASSERT_TRUE(NULL != cache_); |
| 92 | 87 |
| 93 if (size_) | 88 if (size_) |
| 94 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); | 89 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); |
| 95 | 90 |
| 96 if (new_eviction_) | 91 if (new_eviction_) |
| 97 cache_impl_->SetNewEviction(); | 92 cache_impl_->SetNewEviction(); |
| 98 | 93 |
| 99 cache_impl_->SetFlags(disk_cache::kNoRandom); | 94 cache_impl_->SetFlags(disk_cache::kNoRandom); |
| 100 TestCompletionCallback cb; | 95 ASSERT_TRUE(cache_impl_->Init()); |
| 101 int rv = cache_impl_->Init(&cb); | |
| 102 ASSERT_EQ(net::OK, cb.GetResult(rv)); | |
| 103 } | 96 } |
| 104 | 97 |
| 105 void DiskCacheTestWithCache::TearDown() { | 98 void DiskCacheTestWithCache::TearDown() { |
| 106 MessageLoop::current()->RunAllPending(); | 99 MessageLoop::current()->RunAllPending(); |
| 107 delete cache_; | 100 delete cache_; |
| 108 if (cache_thread_.IsRunning()) | 101 if (cache_thread_.IsRunning()) |
| 109 cache_thread_.Stop(); | 102 cache_thread_.Stop(); |
| 110 | 103 |
| 111 if (!memory_only_ && integrity_) { | 104 if (!memory_only_ && integrity_) { |
| 112 FilePath path = GetCacheFilePath(); | 105 FilePath path = GetCacheFilePath(); |
| 113 EXPECT_TRUE(CheckCacheIntegrity(path, new_eviction_)); | 106 EXPECT_TRUE(CheckCacheIntegrity(path, new_eviction_)); |
| 114 } | 107 } |
| 115 | 108 |
| 116 PlatformTest::TearDown(); | 109 PlatformTest::TearDown(); |
| 117 } | 110 } |
| 118 | 111 |
| 119 // We are expected to leak memory when simulating crashes. | 112 // We are expected to leak memory when simulating crashes. |
| 120 void DiskCacheTestWithCache::SimulateCrash() { | 113 void DiskCacheTestWithCache::SimulateCrash() { |
| 121 ASSERT_TRUE(implementation_ && !memory_only_); | 114 ASSERT_TRUE(implementation_ && !memory_only_); |
| 122 TestCompletionCallback cb; | |
| 123 int rv = cache_impl_->FlushQueueForTest(&cb); | |
| 124 ASSERT_EQ(net::OK, cb.GetResult(rv)); | |
| 125 cache_impl_->ClearRefCountForTest(); | 115 cache_impl_->ClearRefCountForTest(); |
| 126 | 116 |
| 127 delete cache_impl_; | 117 delete cache_impl_; |
| 128 FilePath path = GetCacheFilePath(); | 118 FilePath path = GetCacheFilePath(); |
| 129 EXPECT_TRUE(CheckCacheIntegrity(path, new_eviction_)); | 119 EXPECT_TRUE(CheckCacheIntegrity(path, new_eviction_)); |
| 130 | 120 |
| 131 InitDiskCacheImpl(path); | 121 InitDiskCacheImpl(path); |
| 132 } | 122 } |
| 133 | 123 |
| 134 void DiskCacheTestWithCache::SetTestMode() { | 124 void DiskCacheTestWithCache::SetTestMode() { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 int rv = cache_->DoomEntriesSince(initial_time, &cb); | 164 int rv = cache_->DoomEntriesSince(initial_time, &cb); |
| 175 return cb.GetResult(rv); | 165 return cb.GetResult(rv); |
| 176 } | 166 } |
| 177 | 167 |
| 178 int DiskCacheTestWithCache::OpenNextEntry(void** iter, | 168 int DiskCacheTestWithCache::OpenNextEntry(void** iter, |
| 179 disk_cache::Entry** next_entry) { | 169 disk_cache::Entry** next_entry) { |
| 180 TestCompletionCallback cb; | 170 TestCompletionCallback cb; |
| 181 int rv = cache_->OpenNextEntry(iter, next_entry, &cb); | 171 int rv = cache_->OpenNextEntry(iter, next_entry, &cb); |
| 182 return cb.GetResult(rv); | 172 return cb.GetResult(rv); |
| 183 } | 173 } |
| 184 | |
| 185 void DiskCacheTestWithCache::FlushQueueForTest() { | |
| 186 if (memory_only_ || !cache_impl_) | |
| 187 return; | |
| 188 | |
| 189 TestCompletionCallback cb; | |
| 190 int rv = cache_impl_->FlushQueueForTest(&cb); | |
| 191 EXPECT_EQ(net::OK, cb.GetResult(rv)); | |
| 192 } | |
| OLD | NEW |