OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 191 |
192 TEST_F(DiskCacheBackendTest, AppCacheKeying) { | 192 TEST_F(DiskCacheBackendTest, AppCacheKeying) { |
193 SetCacheType(net::APP_CACHE); | 193 SetCacheType(net::APP_CACHE); |
194 BackendKeying(); | 194 BackendKeying(); |
195 } | 195 } |
196 | 196 |
197 TEST_F(DiskCacheTest, CreateBackend) { | 197 TEST_F(DiskCacheTest, CreateBackend) { |
198 TestOldCompletionCallback cb; | 198 TestOldCompletionCallback cb; |
199 | 199 |
200 { | 200 { |
201 FilePath path = GetCacheFilePath(); | 201 ASSERT_TRUE(CleanupCacheDir()); |
202 ASSERT_TRUE(DeleteCache(path)); | |
203 base::Thread cache_thread("CacheThread"); | 202 base::Thread cache_thread("CacheThread"); |
204 ASSERT_TRUE(cache_thread.StartWithOptions( | 203 ASSERT_TRUE(cache_thread.StartWithOptions( |
205 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 204 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
206 | 205 |
207 // Test the private factory methods. | 206 // Test the private factory methods. |
208 disk_cache::Backend* cache = NULL; | 207 disk_cache::Backend* cache = NULL; |
209 int rv = disk_cache::BackendImpl::CreateBackend( | 208 int rv = disk_cache::BackendImpl::CreateBackend( |
210 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, | 209 cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, |
211 cache_thread.message_loop_proxy(), NULL, &cache, &cb); | 210 cache_thread.message_loop_proxy(), NULL, &cache, &cb); |
212 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 211 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
213 ASSERT_TRUE(cache); | 212 ASSERT_TRUE(cache); |
214 delete cache; | 213 delete cache; |
215 | 214 |
216 cache = disk_cache::MemBackendImpl::CreateBackend(0, NULL); | 215 cache = disk_cache::MemBackendImpl::CreateBackend(0, NULL); |
217 ASSERT_TRUE(cache); | 216 ASSERT_TRUE(cache); |
218 delete cache; | 217 delete cache; |
219 cache = NULL; | 218 cache = NULL; |
220 | 219 |
221 // Now test the public API. | 220 // Now test the public API. |
222 rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false, | 221 rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, cache_path_, 0, false, |
223 cache_thread.message_loop_proxy(), | 222 cache_thread.message_loop_proxy(), |
224 NULL, &cache, &cb); | 223 NULL, &cache, &cb); |
225 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 224 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
226 ASSERT_TRUE(cache); | 225 ASSERT_TRUE(cache); |
227 delete cache; | 226 delete cache; |
228 cache = NULL; | 227 cache = NULL; |
229 | 228 |
230 rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE, FilePath(), 0, false, | 229 rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE, FilePath(), 0, false, |
231 NULL, NULL, &cache, &cb); | 230 NULL, NULL, &cache, &cb); |
232 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 231 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
233 ASSERT_TRUE(cache); | 232 ASSERT_TRUE(cache); |
234 delete cache; | 233 delete cache; |
235 } | 234 } |
236 | 235 |
237 MessageLoop::current()->RunAllPending(); | 236 MessageLoop::current()->RunAllPending(); |
238 } | 237 } |
239 | 238 |
240 TEST_F(DiskCacheBackendTest, ExternalFiles) { | 239 TEST_F(DiskCacheBackendTest, ExternalFiles) { |
241 InitCache(); | 240 InitCache(); |
242 // First, let's create a file on the folder. | 241 // First, let's create a file on the folder. |
243 FilePath filename = GetCacheFilePath().AppendASCII("f_000001"); | 242 FilePath filename = cache_path_.AppendASCII("f_000001"); |
244 | 243 |
245 const int kSize = 50; | 244 const int kSize = 50; |
246 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); | 245 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); |
247 CacheTestFillBuffer(buffer1->data(), kSize, false); | 246 CacheTestFillBuffer(buffer1->data(), kSize, false); |
248 ASSERT_EQ(kSize, file_util::WriteFile(filename, buffer1->data(), kSize)); | 247 ASSERT_EQ(kSize, file_util::WriteFile(filename, buffer1->data(), kSize)); |
249 | 248 |
250 // Now let's create a file with the cache. | 249 // Now let's create a file with the cache. |
251 disk_cache::Entry* entry; | 250 disk_cache::Entry* entry; |
252 ASSERT_EQ(net::OK, CreateEntry("key", &entry)); | 251 ASSERT_EQ(net::OK, CreateEntry("key", &entry)); |
253 ASSERT_EQ(0, WriteData(entry, 0, 20000, buffer1, 0, false)); | 252 ASSERT_EQ(0, WriteData(entry, 0, 20000, buffer1, 0, false)); |
254 entry->Close(); | 253 entry->Close(); |
255 | 254 |
256 // And verify that the first file is still there. | 255 // And verify that the first file is still there. |
257 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize)); | 256 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize)); |
258 ASSERT_EQ(kSize, file_util::ReadFile(filename, buffer2->data(), kSize)); | 257 ASSERT_EQ(kSize, file_util::ReadFile(filename, buffer2->data(), kSize)); |
259 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize)); | 258 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize)); |
260 } | 259 } |
261 | 260 |
262 // Tests that we deal with file-level pending operations at destruction time. | 261 // Tests that we deal with file-level pending operations at destruction time. |
263 TEST_F(DiskCacheTest, ShutdownWithPendingIO) { | 262 TEST_F(DiskCacheTest, ShutdownWithPendingIO) { |
264 TestOldCompletionCallback cb; | 263 TestOldCompletionCallback cb; |
265 | 264 |
266 { | 265 { |
267 FilePath path = GetCacheFilePath(); | 266 ASSERT_TRUE(CleanupCacheDir()); |
268 ASSERT_TRUE(DeleteCache(path)); | |
269 base::Thread cache_thread("CacheThread"); | 267 base::Thread cache_thread("CacheThread"); |
270 ASSERT_TRUE(cache_thread.StartWithOptions( | 268 ASSERT_TRUE(cache_thread.StartWithOptions( |
271 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 269 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
272 | 270 |
273 disk_cache::Backend* cache; | 271 disk_cache::Backend* cache; |
274 int rv = disk_cache::BackendImpl::CreateBackend( | 272 int rv = disk_cache::BackendImpl::CreateBackend( |
275 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, | 273 cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, |
276 base::MessageLoopProxy::current(), NULL, | 274 base::MessageLoopProxy::current(), NULL, |
277 &cache, &cb); | 275 &cache, &cb); |
278 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 276 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
279 | 277 |
280 disk_cache::EntryImpl* entry; | 278 disk_cache::EntryImpl* entry; |
281 rv = cache->CreateEntry("some key", | 279 rv = cache->CreateEntry("some key", |
282 reinterpret_cast<disk_cache::Entry**>(&entry), &cb); | 280 reinterpret_cast<disk_cache::Entry**>(&entry), &cb); |
283 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 281 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
284 | 282 |
285 const int kSize = 25000; | 283 const int kSize = 25000; |
(...skipping 23 matching lines...) Expand all Loading... |
309 } | 307 } |
310 | 308 |
311 MessageLoop::current()->RunAllPending(); | 309 MessageLoop::current()->RunAllPending(); |
312 } | 310 } |
313 | 311 |
314 // Tests that we deal with background-thread pending operations. | 312 // Tests that we deal with background-thread pending operations. |
315 TEST_F(DiskCacheTest, ShutdownWithPendingIO2) { | 313 TEST_F(DiskCacheTest, ShutdownWithPendingIO2) { |
316 TestOldCompletionCallback cb; | 314 TestOldCompletionCallback cb; |
317 | 315 |
318 { | 316 { |
319 FilePath path = GetCacheFilePath(); | 317 ASSERT_TRUE(CleanupCacheDir()); |
320 ASSERT_TRUE(DeleteCache(path)); | |
321 base::Thread cache_thread("CacheThread"); | 318 base::Thread cache_thread("CacheThread"); |
322 ASSERT_TRUE(cache_thread.StartWithOptions( | 319 ASSERT_TRUE(cache_thread.StartWithOptions( |
323 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 320 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
324 | 321 |
325 disk_cache::Backend* cache; | 322 disk_cache::Backend* cache; |
326 int rv = disk_cache::BackendImpl::CreateBackend( | 323 int rv = disk_cache::BackendImpl::CreateBackend( |
327 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, | 324 cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, |
328 cache_thread.message_loop_proxy(), NULL, &cache, &cb); | 325 cache_thread.message_loop_proxy(), NULL, &cache, &cb); |
329 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 326 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
330 | 327 |
331 disk_cache::Entry* entry; | 328 disk_cache::Entry* entry; |
332 rv = cache->CreateEntry("some key", &entry, &cb); | 329 rv = cache->CreateEntry("some key", &entry, &cb); |
333 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 330 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
334 | 331 |
335 const int kSize = 25000; | 332 const int kSize = 25000; |
336 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); | 333 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); |
337 CacheTestFillBuffer(buffer->data(), kSize, false); | 334 CacheTestFillBuffer(buffer->data(), kSize, false); |
338 | 335 |
339 rv = entry->WriteData(0, 0, buffer, kSize, &cb, false); | 336 rv = entry->WriteData(0, 0, buffer, kSize, &cb, false); |
340 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 337 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
341 | 338 |
342 entry->Close(); | 339 entry->Close(); |
343 | 340 |
344 // The cache destructor will see two pending operations here. | 341 // The cache destructor will see two pending operations here. |
345 delete cache; | 342 delete cache; |
346 } | 343 } |
347 | 344 |
348 MessageLoop::current()->RunAllPending(); | 345 MessageLoop::current()->RunAllPending(); |
349 } | 346 } |
350 | 347 |
351 TEST_F(DiskCacheTest, TruncatedIndex) { | 348 TEST_F(DiskCacheTest, TruncatedIndex) { |
352 FilePath path = GetCacheFilePath(); | 349 ASSERT_TRUE(CleanupCacheDir()); |
353 ASSERT_TRUE(DeleteCache(path)); | 350 FilePath index = cache_path_.AppendASCII("index"); |
354 FilePath index = path.AppendASCII("index"); | |
355 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5)); | 351 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5)); |
356 | 352 |
357 base::Thread cache_thread("CacheThread"); | 353 base::Thread cache_thread("CacheThread"); |
358 ASSERT_TRUE(cache_thread.StartWithOptions( | 354 ASSERT_TRUE(cache_thread.StartWithOptions( |
359 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 355 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
360 TestOldCompletionCallback cb; | 356 TestOldCompletionCallback cb; |
361 | 357 |
362 disk_cache::Backend* backend = NULL; | 358 disk_cache::Backend* backend = NULL; |
363 int rv = disk_cache::BackendImpl::CreateBackend( | 359 int rv = disk_cache::BackendImpl::CreateBackend( |
364 path, false, 0, net::DISK_CACHE, disk_cache::kNone, | 360 cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNone, |
365 cache_thread.message_loop_proxy(), NULL, &backend, &cb); | 361 cache_thread.message_loop_proxy(), NULL, &backend, &cb); |
366 ASSERT_NE(net::OK, cb.GetResult(rv)); | 362 ASSERT_NE(net::OK, cb.GetResult(rv)); |
367 | 363 |
368 ASSERT_TRUE(backend == NULL); | 364 ASSERT_TRUE(backend == NULL); |
369 delete backend; | 365 delete backend; |
370 } | 366 } |
371 | 367 |
372 void DiskCacheBackendTest::BackendSetSize() { | 368 void DiskCacheBackendTest::BackendSetSize() { |
373 SetDirectMode(); | 369 SetDirectMode(); |
374 const int cache_size = 0x10000; // 64 kB | 370 const int cache_size = 0x10000; // 64 kB |
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1228 ASSERT_TRUE(load); | 1224 ASSERT_TRUE(load); |
1229 // If there is a heavy load, inserting an entry will make another entry | 1225 // If there is a heavy load, inserting an entry will make another entry |
1230 // dirty (on the hash bucket) so two entries are removed. | 1226 // dirty (on the hash bucket) so two entries are removed. |
1231 ASSERT_EQ(num_entries - 1, actual); | 1227 ASSERT_EQ(num_entries - 1, actual); |
1232 } | 1228 } |
1233 | 1229 |
1234 delete cache_; | 1230 delete cache_; |
1235 cache_ = NULL; | 1231 cache_ = NULL; |
1236 cache_impl_ = NULL; | 1232 cache_impl_ = NULL; |
1237 | 1233 |
1238 ASSERT_TRUE(CheckCacheIntegrity(GetCacheFilePath(), new_eviction_, mask)); | 1234 ASSERT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask)); |
1239 success_ = true; | 1235 success_ = true; |
1240 } | 1236 } |
1241 | 1237 |
1242 void DiskCacheBackendTest::BackendRecoverInsert() { | 1238 void DiskCacheBackendTest::BackendRecoverInsert() { |
1243 // Tests with an empty cache. | 1239 // Tests with an empty cache. |
1244 BackendTransaction("insert_empty1", 0, false); | 1240 BackendTransaction("insert_empty1", 0, false); |
1245 ASSERT_TRUE(success_) << "insert_empty1"; | 1241 ASSERT_TRUE(success_) << "insert_empty1"; |
1246 BackendTransaction("insert_empty2", 0, false); | 1242 BackendTransaction("insert_empty2", 0, false); |
1247 ASSERT_TRUE(success_) << "insert_empty2"; | 1243 ASSERT_TRUE(success_) << "insert_empty2"; |
1248 BackendTransaction("insert_empty3", 0, false); | 1244 BackendTransaction("insert_empty3", 0, false); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1339 } | 1335 } |
1340 | 1336 |
1341 TEST_F(DiskCacheBackendTest, NewEvictionRecoverWithEviction) { | 1337 TEST_F(DiskCacheBackendTest, NewEvictionRecoverWithEviction) { |
1342 SetNewEviction(); | 1338 SetNewEviction(); |
1343 BackendRecoverWithEviction(); | 1339 BackendRecoverWithEviction(); |
1344 } | 1340 } |
1345 | 1341 |
1346 // Tests dealing with cache files that cannot be recovered. | 1342 // Tests dealing with cache files that cannot be recovered. |
1347 TEST_F(DiskCacheTest, DeleteOld) { | 1343 TEST_F(DiskCacheTest, DeleteOld) { |
1348 ASSERT_TRUE(CopyTestCache("wrong_version")); | 1344 ASSERT_TRUE(CopyTestCache("wrong_version")); |
1349 FilePath path = GetCacheFilePath(); | |
1350 base::Thread cache_thread("CacheThread"); | 1345 base::Thread cache_thread("CacheThread"); |
1351 ASSERT_TRUE(cache_thread.StartWithOptions( | 1346 ASSERT_TRUE(cache_thread.StartWithOptions( |
1352 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 1347 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
1353 TestOldCompletionCallback cb; | 1348 TestOldCompletionCallback cb; |
1354 | 1349 |
1355 disk_cache::Backend* cache; | 1350 disk_cache::Backend* cache; |
1356 int rv = disk_cache::BackendImpl::CreateBackend( | 1351 int rv = disk_cache::BackendImpl::CreateBackend( |
1357 path, true, 0, net::DISK_CACHE, disk_cache::kNoRandom, | 1352 cache_path_, true, 0, net::DISK_CACHE, disk_cache::kNoRandom, |
1358 cache_thread.message_loop_proxy(), NULL, &cache, &cb); | 1353 cache_thread.message_loop_proxy(), NULL, &cache, &cb); |
1359 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 1354 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
1360 | 1355 |
1361 MessageLoopHelper helper; | 1356 MessageLoopHelper helper; |
1362 | 1357 |
1363 ASSERT_TRUE(NULL != cache); | 1358 ASSERT_TRUE(NULL != cache); |
1364 ASSERT_EQ(0, cache->GetEntryCount()); | 1359 ASSERT_EQ(0, cache->GetEntryCount()); |
1365 | 1360 |
1366 delete cache; | 1361 delete cache; |
1367 } | 1362 } |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1874 } | 1869 } |
1875 | 1870 |
1876 TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty2) { | 1871 TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty2) { |
1877 SetNewEviction(); | 1872 SetNewEviction(); |
1878 BackendNotMarkedButDirty("dirty_entry2"); | 1873 BackendNotMarkedButDirty("dirty_entry2"); |
1879 } | 1874 } |
1880 | 1875 |
1881 // We want to be able to deal with messed up entries on disk. | 1876 // We want to be able to deal with messed up entries on disk. |
1882 void DiskCacheBackendTest::BackendInvalidRankings2() { | 1877 void DiskCacheBackendTest::BackendInvalidRankings2() { |
1883 ASSERT_TRUE(CopyTestCache("bad_rankings")); | 1878 ASSERT_TRUE(CopyTestCache("bad_rankings")); |
1884 FilePath path = GetCacheFilePath(); | |
1885 DisableFirstCleanup(); | 1879 DisableFirstCleanup(); |
1886 InitCache(); | 1880 InitCache(); |
1887 | 1881 |
1888 disk_cache::Entry *entry1, *entry2; | 1882 disk_cache::Entry *entry1, *entry2; |
1889 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1)); | 1883 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1)); |
1890 ASSERT_EQ(net::OK, OpenEntry("some other key", &entry2)); | 1884 ASSERT_EQ(net::OK, OpenEntry("some other key", &entry2)); |
1891 entry2->Close(); | 1885 entry2->Close(); |
1892 | 1886 |
1893 // CheckCacheIntegrity will fail at this point. | 1887 // CheckCacheIntegrity will fail at this point. |
1894 DisableIntegrityCheck(); | 1888 DisableIntegrityCheck(); |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2155 DisableFirstCleanup(); | 2149 DisableFirstCleanup(); |
2156 SetDirectMode(); | 2150 SetDirectMode(); |
2157 SetNewEviction(); | 2151 SetNewEviction(); |
2158 InitCache(); | 2152 InitCache(); |
2159 BackendDisable4(); | 2153 BackendDisable4(); |
2160 } | 2154 } |
2161 | 2155 |
2162 TEST_F(DiskCacheTest, Backend_UsageStats) { | 2156 TEST_F(DiskCacheTest, Backend_UsageStats) { |
2163 MessageLoopHelper helper; | 2157 MessageLoopHelper helper; |
2164 | 2158 |
2165 FilePath path = GetCacheFilePath(); | 2159 ASSERT_TRUE(CleanupCacheDir()); |
2166 ASSERT_TRUE(DeleteCache(path)); | |
2167 scoped_ptr<disk_cache::BackendImpl> cache; | 2160 scoped_ptr<disk_cache::BackendImpl> cache; |
2168 cache.reset(new disk_cache::BackendImpl( | 2161 cache.reset(new disk_cache::BackendImpl( |
2169 path, base::MessageLoopProxy::current(), | 2162 cache_path_, base::MessageLoopProxy::current(), |
2170 NULL)); | 2163 NULL)); |
2171 ASSERT_TRUE(NULL != cache.get()); | 2164 ASSERT_TRUE(NULL != cache.get()); |
2172 cache->SetUnitTestMode(); | 2165 cache->SetUnitTestMode(); |
2173 ASSERT_EQ(net::OK, cache->SyncInit()); | 2166 ASSERT_EQ(net::OK, cache->SyncInit()); |
2174 | 2167 |
2175 // Wait for a callback that never comes... about 2 secs :). The message loop | 2168 // Wait for a callback that never comes... about 2 secs :). The message loop |
2176 // has to run to allow invocation of the usage timer. | 2169 // has to run to allow invocation of the usage timer. |
2177 helper.WaitUntilCacheIoFinished(1); | 2170 helper.WaitUntilCacheIoFinished(1); |
2178 } | 2171 } |
2179 | 2172 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2264 DisableFirstCleanup(); | 2257 DisableFirstCleanup(); |
2265 SetMaxSize(20 * 1024 * 1024); | 2258 SetMaxSize(20 * 1024 * 1024); |
2266 SetNewEviction(); | 2259 SetNewEviction(); |
2267 InitCache(); | 2260 InitCache(); |
2268 BackendDoomAll2(); | 2261 BackendDoomAll2(); |
2269 } | 2262 } |
2270 | 2263 |
2271 // We should be able to create the same entry on multiple simultaneous instances | 2264 // We should be able to create the same entry on multiple simultaneous instances |
2272 // of the cache. | 2265 // of the cache. |
2273 TEST_F(DiskCacheTest, MultipleInstances) { | 2266 TEST_F(DiskCacheTest, MultipleInstances) { |
2274 ScopedTestCache store1; | 2267 ScopedTestCache store1(cache_path_); |
2275 ScopedTestCache store2("cache_test2"); | 2268 ScopedTestCache store2("cache_test2"); |
2276 ScopedTestCache store3("cache_test3"); | 2269 ScopedTestCache store3("cache_test3"); |
2277 base::Thread cache_thread("CacheThread"); | 2270 base::Thread cache_thread("CacheThread"); |
2278 ASSERT_TRUE(cache_thread.StartWithOptions( | 2271 ASSERT_TRUE(cache_thread.StartWithOptions( |
2279 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 2272 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
2280 TestOldCompletionCallback cb; | 2273 TestOldCompletionCallback cb; |
2281 | 2274 |
2282 const int kNumberOfCaches = 2; | 2275 const int kNumberOfCaches = 2; |
2283 disk_cache::Backend* cache[kNumberOfCaches]; | 2276 disk_cache::Backend* cache[kNumberOfCaches]; |
2284 | 2277 |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2482 // Ping the oldest entry. | 2475 // Ping the oldest entry. |
2483 cache_->OnExternalCacheHit("key0"); | 2476 cache_->OnExternalCacheHit("key0"); |
2484 | 2477 |
2485 TrimForTest(false); | 2478 TrimForTest(false); |
2486 | 2479 |
2487 // Make sure the older key remains. | 2480 // Make sure the older key remains. |
2488 EXPECT_EQ(1, cache_->GetEntryCount()); | 2481 EXPECT_EQ(1, cache_->GetEntryCount()); |
2489 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); | 2482 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); |
2490 entry->Close(); | 2483 entry->Close(); |
2491 } | 2484 } |
OLD | NEW |