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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
8 #include "base/port.h" | 8 #include "base/port.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
35 #include "base/win/scoped_handle.h" | 35 #include "base/win/scoped_handle.h" |
36 #endif | 36 #endif |
37 | 37 |
38 using base::Time; | 38 using base::Time; |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 const char kExistingEntryKey[] = "existing entry key"; | 42 const char kExistingEntryKey[] = "existing entry key"; |
43 | 43 |
44 disk_cache::BackendImpl* CreateExistingEntryCache( | 44 scoped_ptr<disk_cache::BackendImpl> CreateExistingEntryCache( |
45 const base::Thread& cache_thread, | 45 const base::Thread& cache_thread, |
46 base::FilePath& cache_path) { | 46 base::FilePath& cache_path) { |
47 net::TestCompletionCallback cb; | 47 net::TestCompletionCallback cb; |
48 | 48 |
49 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl( | 49 scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( |
50 cache_path, cache_thread.message_loop_proxy(), NULL); | 50 cache_path, cache_thread.message_loop_proxy(), NULL)); |
51 int rv = cache->Init(cb.callback()); | 51 int rv = cache->Init(cb.callback()); |
52 if (cb.GetResult(rv) != net::OK) | 52 if (cb.GetResult(rv) != net::OK) |
53 return NULL; | 53 return scoped_ptr<disk_cache::BackendImpl>(); |
54 | 54 |
55 disk_cache::Entry* entry = NULL; | 55 disk_cache::Entry* entry = NULL; |
56 rv = cache->CreateEntry(kExistingEntryKey, &entry, cb.callback()); | 56 rv = cache->CreateEntry(kExistingEntryKey, &entry, cb.callback()); |
57 if (cb.GetResult(rv) != net::OK) { | 57 if (cb.GetResult(rv) != net::OK) |
58 delete cache; | 58 return scoped_ptr<disk_cache::BackendImpl>(); |
59 return NULL; | |
60 } | |
61 entry->Close(); | 59 entry->Close(); |
62 | 60 |
63 return cache; | 61 return cache.Pass(); |
64 } | 62 } |
65 | 63 |
66 } // namespace | 64 } // namespace |
67 | 65 |
68 // Tests that can run with different types of caches. | 66 // Tests that can run with different types of caches. |
69 class DiskCacheBackendTest : public DiskCacheTestWithCache { | 67 class DiskCacheBackendTest : public DiskCacheTestWithCache { |
70 protected: | 68 protected: |
71 void BackendBasics(); | 69 void BackendBasics(); |
72 void BackendKeying(); | 70 void BackendKeying(); |
73 void BackendShutdownWithPendingFileIO(bool fast); | 71 void BackendShutdownWithPendingFileIO(bool fast); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 TEST_F(DiskCacheTest, CreateBackend) { | 259 TEST_F(DiskCacheTest, CreateBackend) { |
262 net::TestCompletionCallback cb; | 260 net::TestCompletionCallback cb; |
263 | 261 |
264 { | 262 { |
265 ASSERT_TRUE(CleanupCacheDir()); | 263 ASSERT_TRUE(CleanupCacheDir()); |
266 base::Thread cache_thread("CacheThread"); | 264 base::Thread cache_thread("CacheThread"); |
267 ASSERT_TRUE(cache_thread.StartWithOptions( | 265 ASSERT_TRUE(cache_thread.StartWithOptions( |
268 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 266 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
269 | 267 |
270 // Test the private factory method(s). | 268 // Test the private factory method(s). |
271 disk_cache::Backend* cache = NULL; | 269 scoped_ptr<disk_cache::Backend> cache; |
272 cache = disk_cache::MemBackendImpl::CreateBackend(0, NULL); | 270 cache = disk_cache::MemBackendImpl::CreateBackend(0, NULL); |
273 ASSERT_TRUE(cache); | 271 ASSERT_TRUE(cache.get()); |
274 delete cache; | 272 cache.reset(); |
275 cache = NULL; | |
276 | 273 |
277 // Now test the public API. | 274 // Now test the public API. |
278 int rv = | 275 int rv = |
279 disk_cache::CreateCacheBackend(net::DISK_CACHE, | 276 disk_cache::CreateCacheBackend(net::DISK_CACHE, |
280 net::CACHE_BACKEND_DEFAULT, | 277 net::CACHE_BACKEND_DEFAULT, |
281 cache_path_, | 278 cache_path_, |
282 0, | 279 0, |
283 false, | 280 false, |
284 cache_thread.message_loop_proxy().get(), | 281 cache_thread.message_loop_proxy().get(), |
285 NULL, | 282 NULL, |
286 &cache, | 283 &cache, |
287 cb.callback()); | 284 cb.callback()); |
288 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 285 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
289 ASSERT_TRUE(cache); | 286 ASSERT_TRUE(cache.get()); |
290 delete cache; | 287 cache.reset(); |
291 cache = NULL; | |
292 | 288 |
293 rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE, | 289 rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE, |
294 net::CACHE_BACKEND_DEFAULT, | 290 net::CACHE_BACKEND_DEFAULT, |
295 base::FilePath(), 0, | 291 base::FilePath(), 0, |
296 false, NULL, NULL, &cache, | 292 false, NULL, NULL, &cache, |
297 cb.callback()); | 293 cb.callback()); |
298 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 294 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
299 ASSERT_TRUE(cache); | 295 ASSERT_TRUE(cache.get()); |
300 delete cache; | 296 cache.reset(); |
301 } | 297 } |
302 | 298 |
303 base::MessageLoop::current()->RunUntilIdle(); | 299 base::MessageLoop::current()->RunUntilIdle(); |
304 } | 300 } |
305 | 301 |
306 // Tests that |BackendImpl| fails to initialize with a missing file. | 302 // Tests that |BackendImpl| fails to initialize with a missing file. |
307 TEST_F(DiskCacheBackendTest, CreateBackend_MissingFile) { | 303 TEST_F(DiskCacheBackendTest, CreateBackend_MissingFile) { |
308 ASSERT_TRUE(CopyTestCache("bad_entry")); | 304 ASSERT_TRUE(CopyTestCache("bad_entry")); |
309 base::FilePath filename = cache_path_.AppendASCII("data_1"); | 305 base::FilePath filename = cache_path_.AppendASCII("data_1"); |
310 base::DeleteFile(filename, false); | 306 base::DeleteFile(filename, false); |
311 base::Thread cache_thread("CacheThread"); | 307 base::Thread cache_thread("CacheThread"); |
312 ASSERT_TRUE(cache_thread.StartWithOptions( | 308 ASSERT_TRUE(cache_thread.StartWithOptions( |
313 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 309 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
314 net::TestCompletionCallback cb; | 310 net::TestCompletionCallback cb; |
315 | 311 |
316 bool prev = base::ThreadRestrictions::SetIOAllowed(false); | 312 bool prev = base::ThreadRestrictions::SetIOAllowed(false); |
317 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl( | 313 scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( |
318 cache_path_, cache_thread.message_loop_proxy().get(), NULL); | 314 cache_path_, cache_thread.message_loop_proxy().get(), NULL)); |
319 int rv = cache->Init(cb.callback()); | 315 int rv = cache->Init(cb.callback()); |
320 ASSERT_EQ(net::ERR_FAILED, cb.GetResult(rv)); | 316 ASSERT_EQ(net::ERR_FAILED, cb.GetResult(rv)); |
321 base::ThreadRestrictions::SetIOAllowed(prev); | 317 base::ThreadRestrictions::SetIOAllowed(prev); |
322 | 318 |
323 delete cache; | 319 cache.reset(); |
324 DisableIntegrityCheck(); | 320 DisableIntegrityCheck(); |
325 } | 321 } |
326 | 322 |
327 TEST_F(DiskCacheBackendTest, ExternalFiles) { | 323 TEST_F(DiskCacheBackendTest, ExternalFiles) { |
328 InitCache(); | 324 InitCache(); |
329 // First, let's create a file on the folder. | 325 // First, let's create a file on the folder. |
330 base::FilePath filename = cache_path_.AppendASCII("f_000001"); | 326 base::FilePath filename = cache_path_.AppendASCII("f_000001"); |
331 | 327 |
332 const int kSize = 50; | 328 const int kSize = 50; |
333 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); | 329 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 if (rv == net::ERR_IO_PENDING) | 379 if (rv == net::ERR_IO_PENDING) |
384 break; | 380 break; |
385 EXPECT_EQ(kSize, rv); | 381 EXPECT_EQ(kSize, rv); |
386 } | 382 } |
387 | 383 |
388 // Don't call Close() to avoid going through the queue or we'll deadlock | 384 // Don't call Close() to avoid going through the queue or we'll deadlock |
389 // waiting for the operation to finish. | 385 // waiting for the operation to finish. |
390 entry->Release(); | 386 entry->Release(); |
391 | 387 |
392 // The cache destructor will see one pending operation here. | 388 // The cache destructor will see one pending operation here. |
393 delete cache_; | 389 cache_.reset(); |
394 // Prevent the TearDown() to delete the backend again. | |
395 cache_ = NULL; | |
396 | 390 |
397 if (rv == net::ERR_IO_PENDING) { | 391 if (rv == net::ERR_IO_PENDING) { |
398 if (fast) | 392 if (fast) |
399 EXPECT_FALSE(cb.have_result()); | 393 EXPECT_FALSE(cb.have_result()); |
400 else | 394 else |
401 EXPECT_TRUE(cb.have_result()); | 395 EXPECT_TRUE(cb.have_result()); |
402 } | 396 } |
403 } | 397 } |
404 | 398 |
405 base::MessageLoop::current()->RunUntilIdle(); | 399 base::MessageLoop::current()->RunUntilIdle(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 | 435 |
442 CreateBackend(flags, &cache_thread); | 436 CreateBackend(flags, &cache_thread); |
443 | 437 |
444 disk_cache::Entry* entry; | 438 disk_cache::Entry* entry; |
445 int rv = cache_->CreateEntry("some key", &entry, cb.callback()); | 439 int rv = cache_->CreateEntry("some key", &entry, cb.callback()); |
446 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 440 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
447 | 441 |
448 entry->Close(); | 442 entry->Close(); |
449 | 443 |
450 // The cache destructor will see one pending operation here. | 444 // The cache destructor will see one pending operation here. |
451 delete cache_; | 445 cache_.reset(); |
452 // Prevent the TearDown() to delete the backend again. | |
453 cache_ = NULL; | |
454 } | 446 } |
455 | 447 |
456 base::MessageLoop::current()->RunUntilIdle(); | 448 base::MessageLoop::current()->RunUntilIdle(); |
457 } | 449 } |
458 | 450 |
459 TEST_F(DiskCacheBackendTest, ShutdownWithPendingIO) { | 451 TEST_F(DiskCacheBackendTest, ShutdownWithPendingIO) { |
460 BackendShutdownWithPendingIO(false); | 452 BackendShutdownWithPendingIO(false); |
461 } | 453 } |
462 | 454 |
463 // We'll be leaking from this test. | 455 // We'll be leaking from this test. |
(...skipping 15 matching lines...) Expand all Loading... |
479 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 471 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
480 | 472 |
481 disk_cache::BackendFlags flags = | 473 disk_cache::BackendFlags flags = |
482 fast ? disk_cache::kNone : disk_cache::kNoRandom; | 474 fast ? disk_cache::kNone : disk_cache::kNoRandom; |
483 CreateBackend(flags, &cache_thread); | 475 CreateBackend(flags, &cache_thread); |
484 | 476 |
485 disk_cache::Entry* entry; | 477 disk_cache::Entry* entry; |
486 int rv = cache_->CreateEntry("some key", &entry, cb.callback()); | 478 int rv = cache_->CreateEntry("some key", &entry, cb.callback()); |
487 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 479 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
488 | 480 |
489 delete cache_; | 481 cache_.reset(); |
490 // Prevent the TearDown() to delete the backend again. | |
491 cache_ = NULL; | |
492 EXPECT_FALSE(cb.have_result()); | 482 EXPECT_FALSE(cb.have_result()); |
493 } | 483 } |
494 | 484 |
495 base::MessageLoop::current()->RunUntilIdle(); | 485 base::MessageLoop::current()->RunUntilIdle(); |
496 } | 486 } |
497 | 487 |
498 TEST_F(DiskCacheBackendTest, ShutdownWithPendingCreate) { | 488 TEST_F(DiskCacheBackendTest, ShutdownWithPendingCreate) { |
499 BackendShutdownWithPendingCreate(false); | 489 BackendShutdownWithPendingCreate(false); |
500 } | 490 } |
501 | 491 |
502 // We'll be leaking an entry from this test. | 492 // We'll be leaking an entry from this test. |
503 TEST_F(DiskCacheBackendTest, ShutdownWithPendingCreate_Fast) { | 493 TEST_F(DiskCacheBackendTest, ShutdownWithPendingCreate_Fast) { |
504 // The integrity test sets kNoRandom so there's a version mismatch if we don't | 494 // The integrity test sets kNoRandom so there's a version mismatch if we don't |
505 // force new eviction. | 495 // force new eviction. |
506 SetNewEviction(); | 496 SetNewEviction(); |
507 BackendShutdownWithPendingCreate(true); | 497 BackendShutdownWithPendingCreate(true); |
508 } | 498 } |
509 | 499 |
510 TEST_F(DiskCacheTest, TruncatedIndex) { | 500 TEST_F(DiskCacheTest, TruncatedIndex) { |
511 ASSERT_TRUE(CleanupCacheDir()); | 501 ASSERT_TRUE(CleanupCacheDir()); |
512 base::FilePath index = cache_path_.AppendASCII("index"); | 502 base::FilePath index = cache_path_.AppendASCII("index"); |
513 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5)); | 503 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5)); |
514 | 504 |
515 base::Thread cache_thread("CacheThread"); | 505 base::Thread cache_thread("CacheThread"); |
516 ASSERT_TRUE(cache_thread.StartWithOptions( | 506 ASSERT_TRUE(cache_thread.StartWithOptions( |
517 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 507 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
518 net::TestCompletionCallback cb; | 508 net::TestCompletionCallback cb; |
519 | 509 |
520 disk_cache::Backend* backend = NULL; | 510 scoped_ptr<disk_cache::Backend> backend; |
521 int rv = | 511 int rv = |
522 disk_cache::CreateCacheBackend(net::DISK_CACHE, | 512 disk_cache::CreateCacheBackend(net::DISK_CACHE, |
523 net::CACHE_BACKEND_BLOCKFILE, | 513 net::CACHE_BACKEND_BLOCKFILE, |
524 cache_path_, | 514 cache_path_, |
525 0, | 515 0, |
526 false, | 516 false, |
527 cache_thread.message_loop_proxy().get(), | 517 cache_thread.message_loop_proxy().get(), |
528 NULL, | 518 NULL, |
529 &backend, | 519 &backend, |
530 cb.callback()); | 520 cb.callback()); |
531 ASSERT_NE(net::OK, cb.GetResult(rv)); | 521 ASSERT_NE(net::OK, cb.GetResult(rv)); |
532 | 522 |
533 ASSERT_TRUE(backend == NULL); | 523 ASSERT_FALSE(backend); |
534 delete backend; | |
535 } | 524 } |
536 | 525 |
537 void DiskCacheBackendTest::BackendSetSize() { | 526 void DiskCacheBackendTest::BackendSetSize() { |
538 const int cache_size = 0x10000; // 64 kB | 527 const int cache_size = 0x10000; // 64 kB |
539 SetMaxSize(cache_size); | 528 SetMaxSize(cache_size); |
540 InitCache(); | 529 InitCache(); |
541 | 530 |
542 std::string first("some key"); | 531 std::string first("some key"); |
543 std::string second("something else"); | 532 std::string second("something else"); |
544 disk_cache::Entry* entry; | 533 disk_cache::Entry* entry; |
(...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1596 ASSERT_NE(net::OK, OpenEntry(key, &entry1)); | 1585 ASSERT_NE(net::OK, OpenEntry(key, &entry1)); |
1597 | 1586 |
1598 int actual = cache_->GetEntryCount(); | 1587 int actual = cache_->GetEntryCount(); |
1599 if (num_entries != actual) { | 1588 if (num_entries != actual) { |
1600 ASSERT_TRUE(load); | 1589 ASSERT_TRUE(load); |
1601 // If there is a heavy load, inserting an entry will make another entry | 1590 // If there is a heavy load, inserting an entry will make another entry |
1602 // dirty (on the hash bucket) so two entries are removed. | 1591 // dirty (on the hash bucket) so two entries are removed. |
1603 ASSERT_EQ(num_entries - 1, actual); | 1592 ASSERT_EQ(num_entries - 1, actual); |
1604 } | 1593 } |
1605 | 1594 |
1606 delete cache_; | 1595 cache_.reset(); |
1607 cache_ = NULL; | |
1608 cache_impl_ = NULL; | 1596 cache_impl_ = NULL; |
1609 | 1597 |
1610 ASSERT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask)); | 1598 ASSERT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask)); |
1611 success_ = true; | 1599 success_ = true; |
1612 } | 1600 } |
1613 | 1601 |
1614 void DiskCacheBackendTest::BackendRecoverInsert() { | 1602 void DiskCacheBackendTest::BackendRecoverInsert() { |
1615 // Tests with an empty cache. | 1603 // Tests with an empty cache. |
1616 BackendTransaction("insert_empty1", 0, false); | 1604 BackendTransaction("insert_empty1", 0, false); |
1617 ASSERT_TRUE(success_) << "insert_empty1"; | 1605 ASSERT_TRUE(success_) << "insert_empty1"; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1716 } | 1704 } |
1717 | 1705 |
1718 // Tests that the |BackendImpl| fails to start with the wrong cache version. | 1706 // Tests that the |BackendImpl| fails to start with the wrong cache version. |
1719 TEST_F(DiskCacheTest, WrongVersion) { | 1707 TEST_F(DiskCacheTest, WrongVersion) { |
1720 ASSERT_TRUE(CopyTestCache("wrong_version")); | 1708 ASSERT_TRUE(CopyTestCache("wrong_version")); |
1721 base::Thread cache_thread("CacheThread"); | 1709 base::Thread cache_thread("CacheThread"); |
1722 ASSERT_TRUE(cache_thread.StartWithOptions( | 1710 ASSERT_TRUE(cache_thread.StartWithOptions( |
1723 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 1711 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
1724 net::TestCompletionCallback cb; | 1712 net::TestCompletionCallback cb; |
1725 | 1713 |
1726 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl( | 1714 scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( |
1727 cache_path_, cache_thread.message_loop_proxy().get(), NULL); | 1715 cache_path_, cache_thread.message_loop_proxy().get(), NULL)); |
1728 int rv = cache->Init(cb.callback()); | 1716 int rv = cache->Init(cb.callback()); |
1729 ASSERT_EQ(net::ERR_FAILED, cb.GetResult(rv)); | 1717 ASSERT_EQ(net::ERR_FAILED, cb.GetResult(rv)); |
1730 | |
1731 delete cache; | |
1732 } | 1718 } |
1733 | 1719 |
1734 class BadEntropyProvider : public base::FieldTrial::EntropyProvider { | 1720 class BadEntropyProvider : public base::FieldTrial::EntropyProvider { |
1735 public: | 1721 public: |
1736 virtual ~BadEntropyProvider() {} | 1722 virtual ~BadEntropyProvider() {} |
1737 | 1723 |
1738 virtual double GetEntropyForTrial(const std::string& trial_name, | 1724 virtual double GetEntropyForTrial(const std::string& trial_name, |
1739 uint32 randomization_seed) const OVERRIDE { | 1725 uint32 randomization_seed) const OVERRIDE { |
1740 return 0.5; | 1726 return 0.5; |
1741 } | 1727 } |
1742 }; | 1728 }; |
1743 | 1729 |
1744 // Tests that the disk cache successfully joins the control group, dropping the | 1730 // Tests that the disk cache successfully joins the control group, dropping the |
1745 // existing cache in favour of a new empty cache. | 1731 // existing cache in favour of a new empty cache. |
1746 TEST_F(DiskCacheTest, SimpleCacheControlJoin) { | 1732 TEST_F(DiskCacheTest, SimpleCacheControlJoin) { |
1747 base::Thread cache_thread("CacheThread"); | 1733 base::Thread cache_thread("CacheThread"); |
1748 ASSERT_TRUE(cache_thread.StartWithOptions( | 1734 ASSERT_TRUE(cache_thread.StartWithOptions( |
1749 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 1735 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
1750 | 1736 |
1751 disk_cache::BackendImpl* cache = CreateExistingEntryCache(cache_thread, | 1737 scoped_ptr<disk_cache::BackendImpl> cache = |
1752 cache_path_); | 1738 CreateExistingEntryCache(cache_thread, cache_path_); |
1753 ASSERT_TRUE(cache); | 1739 ASSERT_TRUE(cache.get()); |
1754 delete cache; | 1740 cache.reset(); |
1755 cache = NULL; | |
1756 | 1741 |
1757 // Instantiate the SimpleCacheTrial, forcing this run into the | 1742 // Instantiate the SimpleCacheTrial, forcing this run into the |
1758 // ExperimentControl group. | 1743 // ExperimentControl group. |
1759 base::FieldTrialList field_trial_list(new BadEntropyProvider()); | 1744 base::FieldTrialList field_trial_list(new BadEntropyProvider()); |
1760 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", | 1745 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", |
1761 "ExperimentControl"); | 1746 "ExperimentControl"); |
1762 net::TestCompletionCallback cb; | 1747 net::TestCompletionCallback cb; |
1763 disk_cache::Backend* base_cache = NULL; | 1748 scoped_ptr<disk_cache::Backend> base_cache; |
1764 int rv = | 1749 int rv = |
1765 disk_cache::CreateCacheBackend(net::DISK_CACHE, | 1750 disk_cache::CreateCacheBackend(net::DISK_CACHE, |
1766 net::CACHE_BACKEND_BLOCKFILE, | 1751 net::CACHE_BACKEND_BLOCKFILE, |
1767 cache_path_, | 1752 cache_path_, |
1768 0, | 1753 0, |
1769 true, | 1754 true, |
1770 cache_thread.message_loop_proxy().get(), | 1755 cache_thread.message_loop_proxy().get(), |
1771 NULL, | 1756 NULL, |
1772 &base_cache, | 1757 &base_cache, |
1773 cb.callback()); | 1758 cb.callback()); |
1774 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 1759 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
1775 cache = static_cast<disk_cache::BackendImpl*>(base_cache); | |
1776 EXPECT_EQ(0, base_cache->GetEntryCount()); | 1760 EXPECT_EQ(0, base_cache->GetEntryCount()); |
1777 delete cache; | |
1778 } | 1761 } |
1779 | 1762 |
1780 // Tests that the disk cache can restart in the control group preserving | 1763 // Tests that the disk cache can restart in the control group preserving |
1781 // existing entries. | 1764 // existing entries. |
1782 TEST_F(DiskCacheTest, SimpleCacheControlRestart) { | 1765 TEST_F(DiskCacheTest, SimpleCacheControlRestart) { |
1783 // Instantiate the SimpleCacheTrial, forcing this run into the | 1766 // Instantiate the SimpleCacheTrial, forcing this run into the |
1784 // ExperimentControl group. | 1767 // ExperimentControl group. |
1785 base::FieldTrialList field_trial_list(new BadEntropyProvider()); | 1768 base::FieldTrialList field_trial_list(new BadEntropyProvider()); |
1786 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", | 1769 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", |
1787 "ExperimentControl"); | 1770 "ExperimentControl"); |
1788 | 1771 |
1789 base::Thread cache_thread("CacheThread"); | 1772 base::Thread cache_thread("CacheThread"); |
1790 ASSERT_TRUE(cache_thread.StartWithOptions( | 1773 ASSERT_TRUE(cache_thread.StartWithOptions( |
1791 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 1774 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
1792 | 1775 |
1793 disk_cache::BackendImpl* cache = CreateExistingEntryCache(cache_thread, | 1776 scoped_ptr<disk_cache::BackendImpl> cache = |
1794 cache_path_); | 1777 CreateExistingEntryCache(cache_thread, cache_path_); |
1795 ASSERT_TRUE(cache); | 1778 ASSERT_TRUE(cache.get()); |
1796 delete cache; | |
1797 cache = NULL; | |
1798 | 1779 |
1799 net::TestCompletionCallback cb; | 1780 net::TestCompletionCallback cb; |
1800 | 1781 |
1801 const int kRestartCount = 5; | 1782 const int kRestartCount = 5; |
1802 for (int i=0; i < kRestartCount; ++i) { | 1783 for (int i=0; i < kRestartCount; ++i) { |
1803 cache = new disk_cache::BackendImpl(cache_path_, | 1784 cache.reset(new disk_cache::BackendImpl( |
1804 cache_thread.message_loop_proxy(), | 1785 cache_path_, cache_thread.message_loop_proxy(), NULL)); |
1805 NULL); | |
1806 int rv = cache->Init(cb.callback()); | 1786 int rv = cache->Init(cb.callback()); |
1807 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 1787 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
1808 EXPECT_EQ(1, cache->GetEntryCount()); | 1788 EXPECT_EQ(1, cache->GetEntryCount()); |
1809 | 1789 |
1810 disk_cache::Entry* entry = NULL; | 1790 disk_cache::Entry* entry = NULL; |
1811 rv = cache->OpenEntry(kExistingEntryKey, &entry, cb.callback()); | 1791 rv = cache->OpenEntry(kExistingEntryKey, &entry, cb.callback()); |
1812 EXPECT_EQ(net::OK, cb.GetResult(rv)); | 1792 EXPECT_EQ(net::OK, cb.GetResult(rv)); |
1813 EXPECT_TRUE(entry); | 1793 EXPECT_TRUE(entry); |
1814 entry->Close(); | 1794 entry->Close(); |
1815 delete cache; | |
1816 cache = NULL; | |
1817 } | 1795 } |
1818 } | 1796 } |
1819 | 1797 |
1820 // Tests that the disk cache can leave the control group preserving existing | 1798 // Tests that the disk cache can leave the control group preserving existing |
1821 // entries. | 1799 // entries. |
1822 TEST_F(DiskCacheTest, SimpleCacheControlLeave) { | 1800 TEST_F(DiskCacheTest, SimpleCacheControlLeave) { |
1823 base::Thread cache_thread("CacheThread"); | 1801 base::Thread cache_thread("CacheThread"); |
1824 ASSERT_TRUE(cache_thread.StartWithOptions( | 1802 ASSERT_TRUE(cache_thread.StartWithOptions( |
1825 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 1803 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
1826 | 1804 |
1827 { | 1805 { |
1828 // Instantiate the SimpleCacheTrial, forcing this run into the | 1806 // Instantiate the SimpleCacheTrial, forcing this run into the |
1829 // ExperimentControl group. | 1807 // ExperimentControl group. |
1830 base::FieldTrialList field_trial_list(new BadEntropyProvider()); | 1808 base::FieldTrialList field_trial_list(new BadEntropyProvider()); |
1831 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", | 1809 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", |
1832 "ExperimentControl"); | 1810 "ExperimentControl"); |
1833 | 1811 |
1834 disk_cache::BackendImpl* cache = CreateExistingEntryCache(cache_thread, | 1812 scoped_ptr<disk_cache::BackendImpl> cache = |
1835 cache_path_); | 1813 CreateExistingEntryCache(cache_thread, cache_path_); |
1836 ASSERT_TRUE(cache); | 1814 ASSERT_TRUE(cache.get()); |
1837 delete cache; | |
1838 } | 1815 } |
1839 | 1816 |
1840 // Instantiate the SimpleCacheTrial, forcing this run into the | 1817 // Instantiate the SimpleCacheTrial, forcing this run into the |
1841 // ExperimentNo group. | 1818 // ExperimentNo group. |
1842 base::FieldTrialList field_trial_list(new BadEntropyProvider()); | 1819 base::FieldTrialList field_trial_list(new BadEntropyProvider()); |
1843 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", "ExperimentNo"); | 1820 base::FieldTrialList::CreateFieldTrial("SimpleCacheTrial", "ExperimentNo"); |
1844 net::TestCompletionCallback cb; | 1821 net::TestCompletionCallback cb; |
1845 | 1822 |
1846 const int kRestartCount = 5; | 1823 const int kRestartCount = 5; |
1847 for (int i = 0; i < kRestartCount; ++i) { | 1824 for (int i = 0; i < kRestartCount; ++i) { |
1848 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl( | 1825 scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( |
1849 cache_path_, cache_thread.message_loop_proxy(), NULL); | 1826 cache_path_, cache_thread.message_loop_proxy(), NULL)); |
1850 int rv = cache->Init(cb.callback()); | 1827 int rv = cache->Init(cb.callback()); |
1851 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 1828 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
1852 EXPECT_EQ(1, cache->GetEntryCount()); | 1829 EXPECT_EQ(1, cache->GetEntryCount()); |
1853 | 1830 |
1854 disk_cache::Entry* entry = NULL; | 1831 disk_cache::Entry* entry = NULL; |
1855 rv = cache->OpenEntry(kExistingEntryKey, &entry, cb.callback()); | 1832 rv = cache->OpenEntry(kExistingEntryKey, &entry, cb.callback()); |
1856 EXPECT_EQ(net::OK, cb.GetResult(rv)); | 1833 EXPECT_EQ(net::OK, cb.GetResult(rv)); |
1857 EXPECT_TRUE(entry); | 1834 EXPECT_TRUE(entry); |
1858 entry->Close(); | 1835 entry->Close(); |
1859 delete cache; | |
1860 cache = NULL; | |
1861 } | 1836 } |
1862 } | 1837 } |
1863 | 1838 |
1864 // Tests that the cache is properly restarted on recovery error. | 1839 // Tests that the cache is properly restarted on recovery error. |
1865 TEST_F(DiskCacheBackendTest, DeleteOld) { | 1840 TEST_F(DiskCacheBackendTest, DeleteOld) { |
1866 ASSERT_TRUE(CopyTestCache("wrong_version")); | 1841 ASSERT_TRUE(CopyTestCache("wrong_version")); |
1867 SetNewEviction(); | 1842 SetNewEviction(); |
1868 base::Thread cache_thread("CacheThread"); | 1843 base::Thread cache_thread("CacheThread"); |
1869 ASSERT_TRUE(cache_thread.StartWithOptions( | 1844 ASSERT_TRUE(cache_thread.StartWithOptions( |
1870 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 1845 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
1871 | 1846 |
1872 net::TestCompletionCallback cb; | 1847 net::TestCompletionCallback cb; |
1873 bool prev = base::ThreadRestrictions::SetIOAllowed(false); | 1848 bool prev = base::ThreadRestrictions::SetIOAllowed(false); |
1874 base::FilePath path(cache_path_); | 1849 base::FilePath path(cache_path_); |
1875 int rv = | 1850 int rv = |
1876 disk_cache::CreateCacheBackend(net::DISK_CACHE, | 1851 disk_cache::CreateCacheBackend(net::DISK_CACHE, |
1877 net::CACHE_BACKEND_BLOCKFILE, | 1852 net::CACHE_BACKEND_BLOCKFILE, |
1878 path, | 1853 path, |
1879 0, | 1854 0, |
1880 true, | 1855 true, |
1881 cache_thread.message_loop_proxy().get(), | 1856 cache_thread.message_loop_proxy().get(), |
1882 NULL, | 1857 NULL, |
1883 &cache_, | 1858 &cache_, |
1884 cb.callback()); | 1859 cb.callback()); |
1885 path.clear(); // Make sure path was captured by the previous call. | 1860 path.clear(); // Make sure path was captured by the previous call. |
1886 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 1861 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
1887 base::ThreadRestrictions::SetIOAllowed(prev); | 1862 base::ThreadRestrictions::SetIOAllowed(prev); |
1888 delete cache_; | 1863 cache_.reset(); |
1889 cache_ = NULL; | |
1890 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_)); | 1864 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_)); |
1891 } | 1865 } |
1892 | 1866 |
1893 // We want to be able to deal with messed up entries on disk. | 1867 // We want to be able to deal with messed up entries on disk. |
1894 void DiskCacheBackendTest::BackendInvalidEntry2() { | 1868 void DiskCacheBackendTest::BackendInvalidEntry2() { |
1895 ASSERT_TRUE(CopyTestCache("bad_entry")); | 1869 ASSERT_TRUE(CopyTestCache("bad_entry")); |
1896 DisableFirstCleanup(); | 1870 DisableFirstCleanup(); |
1897 InitCache(); | 1871 InitCache(); |
1898 | 1872 |
1899 disk_cache::Entry *entry1, *entry2; | 1873 disk_cache::Entry *entry1, *entry2; |
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2655 entry->Close(); | 2629 entry->Close(); |
2656 FlushQueueForTest(); | 2630 FlushQueueForTest(); |
2657 | 2631 |
2658 disk_cache::StatsItems stats; | 2632 disk_cache::StatsItems stats; |
2659 cache_->GetStats(&stats); | 2633 cache_->GetStats(&stats); |
2660 EXPECT_FALSE(stats.empty()); | 2634 EXPECT_FALSE(stats.empty()); |
2661 | 2635 |
2662 disk_cache::StatsItems::value_type hits("Create hit", "0x1"); | 2636 disk_cache::StatsItems::value_type hits("Create hit", "0x1"); |
2663 EXPECT_EQ(1, std::count(stats.begin(), stats.end(), hits)); | 2637 EXPECT_EQ(1, std::count(stats.begin(), stats.end(), hits)); |
2664 | 2638 |
2665 delete cache_; | 2639 cache_.reset(); |
2666 | 2640 |
2667 // Now open the cache and verify that the stats are still there. | 2641 // Now open the cache and verify that the stats are still there. |
2668 DisableFirstCleanup(); | 2642 DisableFirstCleanup(); |
2669 InitCache(); | 2643 InitCache(); |
2670 EXPECT_EQ(1, cache_->GetEntryCount()); | 2644 EXPECT_EQ(1, cache_->GetEntryCount()); |
2671 | 2645 |
2672 stats.clear(); | 2646 stats.clear(); |
2673 cache_->GetStats(&stats); | 2647 cache_->GetStats(&stats); |
2674 EXPECT_FALSE(stats.empty()); | 2648 EXPECT_FALSE(stats.empty()); |
2675 | 2649 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2781 base::ScopedTempDir store1, store2; | 2755 base::ScopedTempDir store1, store2; |
2782 ASSERT_TRUE(store1.CreateUniqueTempDir()); | 2756 ASSERT_TRUE(store1.CreateUniqueTempDir()); |
2783 ASSERT_TRUE(store2.CreateUniqueTempDir()); | 2757 ASSERT_TRUE(store2.CreateUniqueTempDir()); |
2784 | 2758 |
2785 base::Thread cache_thread("CacheThread"); | 2759 base::Thread cache_thread("CacheThread"); |
2786 ASSERT_TRUE(cache_thread.StartWithOptions( | 2760 ASSERT_TRUE(cache_thread.StartWithOptions( |
2787 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 2761 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
2788 net::TestCompletionCallback cb; | 2762 net::TestCompletionCallback cb; |
2789 | 2763 |
2790 const int kNumberOfCaches = 2; | 2764 const int kNumberOfCaches = 2; |
2791 disk_cache::Backend* cache[kNumberOfCaches]; | 2765 scoped_ptr<disk_cache::Backend> cache[kNumberOfCaches]; |
2792 | 2766 |
2793 int rv = | 2767 int rv = |
2794 disk_cache::CreateCacheBackend(net::DISK_CACHE, | 2768 disk_cache::CreateCacheBackend(net::DISK_CACHE, |
2795 net::CACHE_BACKEND_DEFAULT, | 2769 net::CACHE_BACKEND_DEFAULT, |
2796 store1.path(), | 2770 store1.path(), |
2797 0, | 2771 0, |
2798 false, | 2772 false, |
2799 cache_thread.message_loop_proxy().get(), | 2773 cache_thread.message_loop_proxy().get(), |
2800 NULL, | 2774 NULL, |
2801 &cache[0], | 2775 &cache[0], |
2802 cb.callback()); | 2776 cb.callback()); |
2803 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 2777 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
2804 rv = disk_cache::CreateCacheBackend(net::MEDIA_CACHE, | 2778 rv = disk_cache::CreateCacheBackend(net::MEDIA_CACHE, |
2805 net::CACHE_BACKEND_DEFAULT, | 2779 net::CACHE_BACKEND_DEFAULT, |
2806 store2.path(), | 2780 store2.path(), |
2807 0, | 2781 0, |
2808 false, | 2782 false, |
2809 cache_thread.message_loop_proxy().get(), | 2783 cache_thread.message_loop_proxy().get(), |
2810 NULL, | 2784 NULL, |
2811 &cache[1], | 2785 &cache[1], |
2812 cb.callback()); | 2786 cb.callback()); |
2813 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 2787 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
2814 | 2788 |
2815 ASSERT_TRUE(cache[0] != NULL && cache[1] != NULL); | 2789 ASSERT_TRUE(cache[0].get() != NULL && cache[1].get() != NULL); |
2816 | 2790 |
2817 std::string key("the first key"); | 2791 std::string key("the first key"); |
2818 disk_cache::Entry* entry; | 2792 disk_cache::Entry* entry; |
2819 for (int i = 0; i < kNumberOfCaches; i++) { | 2793 for (int i = 0; i < kNumberOfCaches; i++) { |
2820 rv = cache[i]->CreateEntry(key, &entry, cb.callback()); | 2794 rv = cache[i]->CreateEntry(key, &entry, cb.callback()); |
2821 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 2795 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
2822 entry->Close(); | 2796 entry->Close(); |
2823 } | 2797 } |
2824 delete cache[0]; | |
2825 delete cache[1]; | |
2826 } | 2798 } |
2827 | 2799 |
2828 // Test the six regions of the curve that determines the max cache size. | 2800 // Test the six regions of the curve that determines the max cache size. |
2829 TEST_F(DiskCacheTest, AutomaticMaxSize) { | 2801 TEST_F(DiskCacheTest, AutomaticMaxSize) { |
2830 const int kDefaultSize = 80 * 1024 * 1024; | 2802 const int kDefaultSize = 80 * 1024 * 1024; |
2831 int64 large_size = kDefaultSize; | 2803 int64 large_size = kDefaultSize; |
2832 int64 largest_size = kint32max; | 2804 int64 largest_size = kint32max; |
2833 | 2805 |
2834 // Region 1: expected = available * 0.8 | 2806 // Region 1: expected = available * 0.8 |
2835 EXPECT_EQ((kDefaultSize - 1) * 8 / 10, | 2807 EXPECT_EQ((kDefaultSize - 1) * 8 / 10, |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3026 TrimForTest(false); | 2998 TrimForTest(false); |
3027 | 2999 |
3028 // Make sure the older key remains. | 3000 // Make sure the older key remains. |
3029 EXPECT_EQ(1, cache_->GetEntryCount()); | 3001 EXPECT_EQ(1, cache_->GetEntryCount()); |
3030 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); | 3002 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); |
3031 entry->Close(); | 3003 entry->Close(); |
3032 } | 3004 } |
3033 | 3005 |
3034 void DiskCacheBackendTest::TracingBackendBasics() { | 3006 void DiskCacheBackendTest::TracingBackendBasics() { |
3035 InitCache(); | 3007 InitCache(); |
3036 cache_ = new disk_cache::TracingCacheBackend(cache_); | 3008 cache_.reset(new disk_cache::TracingCacheBackend(cache_.Pass())); |
3037 cache_impl_ = NULL; | 3009 cache_impl_ = NULL; |
3038 EXPECT_EQ(net::DISK_CACHE, cache_->GetCacheType()); | 3010 EXPECT_EQ(net::DISK_CACHE, cache_->GetCacheType()); |
3039 if (!simple_cache_mode_) { | 3011 if (!simple_cache_mode_) { |
3040 EXPECT_EQ(0, cache_->GetEntryCount()); | 3012 EXPECT_EQ(0, cache_->GetEntryCount()); |
3041 } | 3013 } |
3042 | 3014 |
3043 net::TestCompletionCallback cb; | 3015 net::TestCompletionCallback cb; |
3044 disk_cache::Entry* entry = NULL; | 3016 disk_cache::Entry* entry = NULL; |
3045 EXPECT_NE(net::OK, OpenEntry("key", &entry)); | 3017 EXPECT_NE(net::OK, OpenEntry("key", &entry)); |
3046 EXPECT_TRUE(NULL == entry); | 3018 EXPECT_TRUE(NULL == entry); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3221 TEST_F(DiskCacheBackendTest, SimpleCacheOverBlockfileCache) { | 3193 TEST_F(DiskCacheBackendTest, SimpleCacheOverBlockfileCache) { |
3222 // Create a cache structure with the |BackendImpl|. | 3194 // Create a cache structure with the |BackendImpl|. |
3223 InitCache(); | 3195 InitCache(); |
3224 disk_cache::Entry* entry; | 3196 disk_cache::Entry* entry; |
3225 const int kSize = 50; | 3197 const int kSize = 50; |
3226 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); | 3198 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); |
3227 CacheTestFillBuffer(buffer->data(), kSize, false); | 3199 CacheTestFillBuffer(buffer->data(), kSize, false); |
3228 ASSERT_EQ(net::OK, CreateEntry("key", &entry)); | 3200 ASSERT_EQ(net::OK, CreateEntry("key", &entry)); |
3229 ASSERT_EQ(0, WriteData(entry, 0, 0, buffer.get(), 0, false)); | 3201 ASSERT_EQ(0, WriteData(entry, 0, 0, buffer.get(), 0, false)); |
3230 entry->Close(); | 3202 entry->Close(); |
3231 delete cache_; | 3203 cache_.reset(); |
3232 cache_ = NULL; | |
3233 | 3204 |
3234 // Check that the |SimpleBackendImpl| does not favor this structure. | 3205 // Check that the |SimpleBackendImpl| does not favor this structure. |
3235 base::Thread cache_thread("CacheThread"); | 3206 base::Thread cache_thread("CacheThread"); |
3236 ASSERT_TRUE(cache_thread.StartWithOptions( | 3207 ASSERT_TRUE(cache_thread.StartWithOptions( |
3237 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 3208 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
3238 disk_cache::SimpleBackendImpl* simple_cache = | 3209 disk_cache::SimpleBackendImpl* simple_cache = |
3239 new disk_cache::SimpleBackendImpl(cache_path_, | 3210 new disk_cache::SimpleBackendImpl(cache_path_, |
3240 0, | 3211 0, |
3241 net::DISK_CACHE, | 3212 net::DISK_CACHE, |
3242 cache_thread.message_loop_proxy().get(), | 3213 cache_thread.message_loop_proxy().get(), |
(...skipping 11 matching lines...) Expand all Loading... |
3254 // Create a cache structure with the |SimpleBackendImpl|. | 3225 // Create a cache structure with the |SimpleBackendImpl|. |
3255 SetSimpleCacheMode(); | 3226 SetSimpleCacheMode(); |
3256 InitCache(); | 3227 InitCache(); |
3257 disk_cache::Entry* entry; | 3228 disk_cache::Entry* entry; |
3258 const int kSize = 50; | 3229 const int kSize = 50; |
3259 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); | 3230 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); |
3260 CacheTestFillBuffer(buffer->data(), kSize, false); | 3231 CacheTestFillBuffer(buffer->data(), kSize, false); |
3261 ASSERT_EQ(net::OK, CreateEntry("key", &entry)); | 3232 ASSERT_EQ(net::OK, CreateEntry("key", &entry)); |
3262 ASSERT_EQ(0, WriteData(entry, 0, 0, buffer.get(), 0, false)); | 3233 ASSERT_EQ(0, WriteData(entry, 0, 0, buffer.get(), 0, false)); |
3263 entry->Close(); | 3234 entry->Close(); |
3264 delete cache_; | 3235 cache_.reset(); |
3265 cache_ = NULL; | |
3266 | 3236 |
3267 // Check that the |BackendImpl| does not favor this structure. | 3237 // Check that the |BackendImpl| does not favor this structure. |
3268 base::Thread cache_thread("CacheThread"); | 3238 base::Thread cache_thread("CacheThread"); |
3269 ASSERT_TRUE(cache_thread.StartWithOptions( | 3239 ASSERT_TRUE(cache_thread.StartWithOptions( |
3270 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 3240 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
3271 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl( | 3241 disk_cache::BackendImpl* cache = new disk_cache::BackendImpl( |
3272 cache_path_, base::MessageLoopProxy::current().get(), NULL); | 3242 cache_path_, base::MessageLoopProxy::current().get(), NULL); |
3273 cache->SetUnitTestMode(); | 3243 cache->SetUnitTestMode(); |
3274 net::TestCompletionCallback cb; | 3244 net::TestCompletionCallback cb; |
3275 int rv = cache->Init(cb.callback()); | 3245 int rv = cache->Init(cb.callback()); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3424 void* iter = NULL; | 3394 void* iter = NULL; |
3425 size_t count = 0; | 3395 size_t count = 0; |
3426 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count)); | 3396 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count)); |
3427 cache_->EndEnumeration(&iter); | 3397 cache_->EndEnumeration(&iter); |
3428 | 3398 |
3429 EXPECT_EQ(key_pool.size(), count); | 3399 EXPECT_EQ(key_pool.size(), count); |
3430 EXPECT_TRUE(keys_to_match.empty()); | 3400 EXPECT_TRUE(keys_to_match.empty()); |
3431 } | 3401 } |
3432 | 3402 |
3433 #endif // !defined(OS_WIN) | 3403 #endif // !defined(OS_WIN) |
OLD | NEW |