| 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 21 matching lines...) Expand all Loading... |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 33 | 33 |
| 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 int kDelayToNextTimestamp = 60; |
| 42 const char kExistingEntryKey[] = "existing entry key"; | 43 const char kExistingEntryKey[] = "existing entry key"; |
| 43 | 44 |
| 44 scoped_ptr<disk_cache::BackendImpl> CreateExistingEntryCache( | 45 scoped_ptr<disk_cache::BackendImpl> CreateExistingEntryCache( |
| 45 const base::Thread& cache_thread, | 46 const base::Thread& cache_thread, |
| 46 base::FilePath& cache_path) { | 47 base::FilePath& cache_path) { |
| 47 net::TestCompletionCallback cb; | 48 net::TestCompletionCallback cb; |
| 48 | 49 |
| 49 scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( | 50 scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( |
| 50 cache_path, cache_thread.message_loop_proxy(), NULL)); | 51 cache_path, cache_thread.message_loop_proxy(), NULL)); |
| 51 int rv = cache->Init(cb.callback()); | 52 int rv = cache->Init(cb.callback()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 85 |
| 85 // Actual tests: | 86 // Actual tests: |
| 86 void BackendBasics(); | 87 void BackendBasics(); |
| 87 void BackendKeying(); | 88 void BackendKeying(); |
| 88 void BackendShutdownWithPendingFileIO(bool fast); | 89 void BackendShutdownWithPendingFileIO(bool fast); |
| 89 void BackendShutdownWithPendingIO(bool fast); | 90 void BackendShutdownWithPendingIO(bool fast); |
| 90 void BackendShutdownWithPendingCreate(bool fast); | 91 void BackendShutdownWithPendingCreate(bool fast); |
| 91 void BackendSetSize(); | 92 void BackendSetSize(); |
| 92 void BackendLoad(); | 93 void BackendLoad(); |
| 93 void BackendChain(); | 94 void BackendChain(); |
| 95 void BucketUse(); |
| 96 void BackendNewEvictionTrim(); |
| 94 void BackendValidEntry(); | 97 void BackendValidEntry(); |
| 95 void BackendInvalidEntry(); | 98 void BackendInvalidEntry(); |
| 96 void BackendInvalidEntryRead(); | 99 void BackendInvalidEntryRead(); |
| 97 void BackendInvalidEntryWithLoad(); | 100 void BackendInvalidEntryWithLoad(); |
| 98 void BackendTrimInvalidEntry(); | 101 void BackendTrimInvalidEntry(); |
| 99 void BackendTrimInvalidEntry2(); | 102 void BackendTrimInvalidEntry2(); |
| 100 void BackendEnumerations(); | 103 void BackendEnumerations(); |
| 101 void BackendEnumerations2(); | 104 void BackendEnumerations2(); |
| 102 void BackendInvalidEntryEnumeration(); | 105 void BackendInvalidEntryEnumeration(); |
| 103 void BackendFixEnumerators(); | 106 void BackendFixEnumerators(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 116 void BackendInvalidEntry11(bool eviction); | 119 void BackendInvalidEntry11(bool eviction); |
| 117 void BackendTrimInvalidEntry12(); | 120 void BackendTrimInvalidEntry12(); |
| 118 void BackendDoomAll(); | 121 void BackendDoomAll(); |
| 119 void BackendDoomAll2(); | 122 void BackendDoomAll2(); |
| 120 void BackendInvalidRankings(); | 123 void BackendInvalidRankings(); |
| 121 void BackendInvalidRankings2(); | 124 void BackendInvalidRankings2(); |
| 122 void BackendDisable(); | 125 void BackendDisable(); |
| 123 void BackendDisable2(); | 126 void BackendDisable2(); |
| 124 void BackendDisable3(); | 127 void BackendDisable3(); |
| 125 void BackendDisable4(); | 128 void BackendDisable4(); |
| 129 void BackendTotalBuffersSize1(); |
| 130 void BackendTotalBuffersSize2(); |
| 131 void BackendUpdateRankForExternalCacheHit(); |
| 126 void TracingBackendBasics(); | 132 void TracingBackendBasics(); |
| 127 }; | 133 }; |
| 128 | 134 |
| 129 int DiskCacheBackendTest::GeneratePendingIO(net::TestCompletionCallback* cb) { | 135 int DiskCacheBackendTest::GeneratePendingIO(net::TestCompletionCallback* cb) { |
| 130 if (!use_current_thread_) { | 136 if (!use_current_thread_) { |
| 131 ADD_FAILURE(); | 137 ADD_FAILURE(); |
| 132 return net::ERR_FAILED; | 138 return net::ERR_FAILED; |
| 133 } | 139 } |
| 134 | 140 |
| 135 disk_cache::Entry* entry; | 141 disk_cache::Entry* entry; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 TEST_F(DiskCacheBackendTest, AppCacheBasics) { | 341 TEST_F(DiskCacheBackendTest, AppCacheBasics) { |
| 336 SetCacheType(net::APP_CACHE); | 342 SetCacheType(net::APP_CACHE); |
| 337 BackendBasics(); | 343 BackendBasics(); |
| 338 } | 344 } |
| 339 | 345 |
| 340 TEST_F(DiskCacheBackendTest, ShaderCacheBasics) { | 346 TEST_F(DiskCacheBackendTest, ShaderCacheBasics) { |
| 341 SetCacheType(net::SHADER_CACHE); | 347 SetCacheType(net::SHADER_CACHE); |
| 342 BackendBasics(); | 348 BackendBasics(); |
| 343 } | 349 } |
| 344 | 350 |
| 351 TEST_F(DiskCacheBackendTest, V3Basics) { |
| 352 UseVersion3(); |
| 353 BackendBasics(); |
| 354 } |
| 355 |
| 345 void DiskCacheBackendTest::BackendKeying() { | 356 void DiskCacheBackendTest::BackendKeying() { |
| 346 InitCache(); | 357 InitCache(); |
| 347 const char* kName1 = "the first key"; | 358 const char* kName1 = "the first key"; |
| 348 const char* kName2 = "the first Key"; | 359 const char* kName2 = "the first Key"; |
| 349 disk_cache::Entry *entry1, *entry2; | 360 disk_cache::Entry *entry1, *entry2; |
| 350 ASSERT_EQ(net::OK, CreateEntry(kName1, &entry1)); | 361 ASSERT_EQ(net::OK, CreateEntry(kName1, &entry1)); |
| 351 | 362 |
| 352 ASSERT_EQ(net::OK, CreateEntry(kName2, &entry2)); | 363 ASSERT_EQ(net::OK, CreateEntry(kName2, &entry2)); |
| 353 EXPECT_TRUE(entry1 != entry2) << "Case sensitive"; | 364 EXPECT_TRUE(entry1 != entry2) << "Case sensitive"; |
| 354 entry2->Close(); | 365 entry2->Close(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 380 buffer2[19999] = '\0'; | 391 buffer2[19999] = '\0'; |
| 381 ASSERT_EQ(net::OK, CreateEntry(buffer2, &entry2)) << "key on external file"; | 392 ASSERT_EQ(net::OK, CreateEntry(buffer2, &entry2)) << "key on external file"; |
| 382 entry2->Close(); | 393 entry2->Close(); |
| 383 entry1->Close(); | 394 entry1->Close(); |
| 384 } | 395 } |
| 385 | 396 |
| 386 TEST_F(DiskCacheBackendTest, Keying) { | 397 TEST_F(DiskCacheBackendTest, Keying) { |
| 387 BackendKeying(); | 398 BackendKeying(); |
| 388 } | 399 } |
| 389 | 400 |
| 401 TEST_F(DiskCacheBackendTest, V3Keying) { |
| 402 UseVersion3(); |
| 403 BackendKeying(); |
| 404 } |
| 405 |
| 390 TEST_F(DiskCacheBackendTest, NewEvictionKeying) { | 406 TEST_F(DiskCacheBackendTest, NewEvictionKeying) { |
| 391 SetNewEviction(); | 407 SetNewEviction(); |
| 392 BackendKeying(); | 408 BackendKeying(); |
| 393 } | 409 } |
| 394 | 410 |
| 411 TEST_F(DiskCacheBackendTest, V3NewEvictionKeying) { |
| 412 UseVersion3(); |
| 413 SetNewEviction(); |
| 414 BackendKeying(); |
| 415 } |
| 416 |
| 395 TEST_F(DiskCacheBackendTest, MemoryOnlyKeying) { | 417 TEST_F(DiskCacheBackendTest, MemoryOnlyKeying) { |
| 396 SetMemoryOnlyMode(); | 418 SetMemoryOnlyMode(); |
| 397 BackendKeying(); | 419 BackendKeying(); |
| 398 } | 420 } |
| 399 | 421 |
| 400 TEST_F(DiskCacheBackendTest, AppCacheKeying) { | 422 TEST_F(DiskCacheBackendTest, AppCacheKeying) { |
| 401 SetCacheType(net::APP_CACHE); | 423 SetCacheType(net::APP_CACHE); |
| 402 BackendKeying(); | 424 BackendKeying(); |
| 403 } | 425 } |
| 404 | 426 |
| 405 TEST_F(DiskCacheBackendTest, ShaderCacheKeying) { | 427 TEST_F(DiskCacheBackendTest, ShaderCacheKeying) { |
| 406 SetCacheType(net::SHADER_CACHE); | 428 SetCacheType(net::SHADER_CACHE); |
| 407 BackendKeying(); | 429 BackendKeying(); |
| 408 } | 430 } |
| 409 | 431 |
| 410 TEST_F(DiskCacheTest, CreateBackend) { | 432 TEST_F(DiskCacheTest, CreateBackend) { |
| 411 net::TestCompletionCallback cb; | 433 net::TestCompletionCallback cb; |
| 412 | 434 |
| 413 { | 435 { |
| 414 ASSERT_TRUE(CleanupCacheDir()); | 436 ASSERT_TRUE(CleanupCacheDir()); |
| 415 base::Thread cache_thread("CacheThread"); | 437 base::Thread cache_thread("CacheThread"); |
| 416 ASSERT_TRUE(cache_thread.StartWithOptions( | 438 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 417 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 439 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 418 | 440 |
| 419 // Test the private factory method(s). | 441 // Test the private factory method(s). |
| 420 scoped_ptr<disk_cache::Backend> cache; | 442 scoped_ptr<disk_cache::Backend> cache; |
| 421 cache = disk_cache::MemBackendImpl::CreateBackend(0, NULL); | 443 cache = disk_cache::MemBackendImpl::CreateBackend(0, NULL); |
| 422 ASSERT_TRUE(cache.get()); | 444 ASSERT_TRUE(cache.get()); |
| 423 cache.reset(); | 445 cache.reset(); |
| 424 | 446 |
| 425 // Now test the public API. | 447 // Now test the public API. |
| 426 int rv = | 448 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, |
| 427 disk_cache::CreateCacheBackend(net::DISK_CACHE, | 449 net::CACHE_BACKEND_DEFAULT, |
| 428 net::CACHE_BACKEND_DEFAULT, | 450 cache_path_, 0, false, |
| 429 cache_path_, | 451 cache_thread.message_loop_proxy(), |
| 430 0, | 452 NULL, &cache, cb.callback()); |
| 431 false, | |
| 432 cache_thread.message_loop_proxy().get(), | |
| 433 NULL, | |
| 434 &cache, | |
| 435 cb.callback()); | |
| 436 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 453 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 437 ASSERT_TRUE(cache.get()); | 454 ASSERT_TRUE(cache.get()); |
| 438 cache.reset(); | 455 cache.reset(); |
| 439 | 456 |
| 440 rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE, | 457 rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE, |
| 441 net::CACHE_BACKEND_DEFAULT, | 458 net::CACHE_BACKEND_DEFAULT, |
| 442 base::FilePath(), 0, | 459 base::FilePath(), 0, |
| 443 false, NULL, NULL, &cache, | 460 false, NULL, NULL, &cache, |
| 444 cb.callback()); | 461 cb.callback()); |
| 445 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 462 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 446 ASSERT_TRUE(cache.get()); | 463 ASSERT_TRUE(cache.get()); |
| 447 cache.reset(); | 464 cache.reset(); |
| 448 } | 465 } |
| 449 | 466 |
| 450 base::MessageLoop::current()->RunUntilIdle(); | 467 base::MessageLoop::current()->RunUntilIdle(); |
| 451 } | 468 } |
| 452 | 469 |
| 453 // Tests that |BackendImpl| fails to initialize with a missing file. | 470 // Tests that |BackendImpl| fails to initialize with a missing file. |
| 454 TEST_F(DiskCacheBackendTest, CreateBackend_MissingFile) { | 471 TEST_F(DiskCacheBackendTest, CreateBackend_MissingFile) { |
| 455 ASSERT_TRUE(CopyTestCache("bad_entry")); | 472 ASSERT_TRUE(CopyTestCache("bad_entry")); |
| 456 base::FilePath filename = cache_path_.AppendASCII("data_1"); | 473 base::FilePath filename = cache_path_.AppendASCII("data_1"); |
| 457 base::DeleteFile(filename, false); | 474 base::DeleteFile(filename, false); |
| 458 base::Thread cache_thread("CacheThread"); | 475 base::Thread cache_thread("CacheThread"); |
| 459 ASSERT_TRUE(cache_thread.StartWithOptions( | 476 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 460 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 477 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 461 net::TestCompletionCallback cb; | 478 net::TestCompletionCallback cb; |
| 462 | 479 |
| 463 bool prev = base::ThreadRestrictions::SetIOAllowed(false); | 480 bool prev = base::ThreadRestrictions::SetIOAllowed(false); |
| 464 scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( | 481 scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( |
| 465 cache_path_, cache_thread.message_loop_proxy().get(), NULL)); | 482 cache_path_, cache_thread.message_loop_proxy().get(), NULL)); |
| 466 int rv = cache->Init(cb.callback()); | 483 int rv = cache->Init(cb.callback()); |
| 467 EXPECT_EQ(net::ERR_FAILED, cb.GetResult(rv)); | 484 EXPECT_EQ(net::ERR_FAILED, cb.GetResult(rv)); |
| 468 base::ThreadRestrictions::SetIOAllowed(prev); | 485 base::ThreadRestrictions::SetIOAllowed(prev); |
| 469 | 486 |
| 470 cache.reset(); | 487 cache.reset(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 489 | 506 |
| 490 // And verify that the first file is still there. | 507 // And verify that the first file is still there. |
| 491 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize)); | 508 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize)); |
| 492 ASSERT_EQ(kSize, file_util::ReadFile(filename, buffer2->data(), kSize)); | 509 ASSERT_EQ(kSize, file_util::ReadFile(filename, buffer2->data(), kSize)); |
| 493 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize)); | 510 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize)); |
| 494 } | 511 } |
| 495 | 512 |
| 496 // Tests that we deal with file-level pending operations at destruction time. | 513 // Tests that we deal with file-level pending operations at destruction time. |
| 497 void DiskCacheBackendTest::BackendShutdownWithPendingFileIO(bool fast) { | 514 void DiskCacheBackendTest::BackendShutdownWithPendingFileIO(bool fast) { |
| 498 ASSERT_TRUE(CleanupCacheDir()); | 515 ASSERT_TRUE(CleanupCacheDir()); |
| 499 uint32 flags = disk_cache::kNoBuffering; | 516 if (fast) |
| 500 if (!fast) | 517 AvoidTestFlag(); |
| 501 flags |= disk_cache::kNoRandom; | |
| 502 | 518 |
| 503 UseCurrentThread(); | 519 UseCurrentThread(); |
| 504 CreateBackend(flags, NULL); | 520 CreateBackend(NULL); |
| 521 SetNoBuffering(); |
| 505 | 522 |
| 506 net::TestCompletionCallback cb; | 523 net::TestCompletionCallback cb; |
| 507 int rv = GeneratePendingIO(&cb); | 524 int rv = GeneratePendingIO(&cb); |
| 508 | 525 |
| 509 // The cache destructor will see one pending operation here. | 526 // The cache destructor will see one pending operation here. |
| 510 cache_.reset(); | 527 cache_.reset(); |
| 511 | 528 |
| 512 if (rv == net::ERR_IO_PENDING) { | 529 if (rv == net::ERR_IO_PENDING) { |
| 513 if (fast || simple_cache_mode_) | 530 if (fast || simple_cache_mode_) |
| 514 EXPECT_FALSE(cb.have_result()); | 531 EXPECT_FALSE(cb.have_result()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 net::DISK_CACHE, net::CACHE_BACKEND_DEFAULT, store.path(), 0, | 571 net::DISK_CACHE, net::CACHE_BACKEND_DEFAULT, store.path(), 0, |
| 555 false, base::MessageLoopProxy::current().get(), NULL, | 572 false, base::MessageLoopProxy::current().get(), NULL, |
| 556 &extra_cache, cb.callback()); | 573 &extra_cache, cb.callback()); |
| 557 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 574 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 558 ASSERT_TRUE(extra_cache.get() != NULL); | 575 ASSERT_TRUE(extra_cache.get() != NULL); |
| 559 | 576 |
| 560 ASSERT_TRUE(CleanupCacheDir()); | 577 ASSERT_TRUE(CleanupCacheDir()); |
| 561 SetNewEviction(); // Match the expected behavior for integrity verification. | 578 SetNewEviction(); // Match the expected behavior for integrity verification. |
| 562 UseCurrentThread(); | 579 UseCurrentThread(); |
| 563 | 580 |
| 564 CreateBackend(disk_cache::kNoBuffering, NULL); | 581 CreateBackend(NULL); |
| 582 SetNoBuffering(); |
| 565 rv = GeneratePendingIO(&cb); | 583 rv = GeneratePendingIO(&cb); |
| 566 | 584 |
| 567 // cache_ has a pending operation, and extra_cache will go away. | 585 // cache_ has a pending operation, and extra_cache will go away. |
| 568 extra_cache.reset(); | 586 extra_cache.reset(); |
| 569 | 587 |
| 570 if (rv == net::ERR_IO_PENDING) | 588 if (rv == net::ERR_IO_PENDING) |
| 571 EXPECT_FALSE(cb.have_result()); | 589 EXPECT_FALSE(cb.have_result()); |
| 572 | 590 |
| 573 base::MessageLoop::current()->RunUntilIdle(); | 591 base::MessageLoop::current()->RunUntilIdle(); |
| 574 | 592 |
| 575 // Wait for the actual operation to complete, or we'll keep a file handle that | 593 // Wait for the actual operation to complete, or we'll keep a file handle that |
| 576 // may cause issues later. | 594 // may cause issues later. |
| 577 rv = cb.GetResult(rv); | 595 rv = cb.GetResult(rv); |
| 578 } | 596 } |
| 579 | 597 |
| 580 // Tests that we deal with background-thread pending operations. | 598 // Tests that we deal with background-thread pending operations. |
| 581 void DiskCacheBackendTest::BackendShutdownWithPendingIO(bool fast) { | 599 void DiskCacheBackendTest::BackendShutdownWithPendingIO(bool fast) { |
| 582 net::TestCompletionCallback cb; | 600 net::TestCompletionCallback cb; |
| 583 | 601 |
| 584 { | 602 { |
| 585 ASSERT_TRUE(CleanupCacheDir()); | 603 ASSERT_TRUE(CleanupCacheDir()); |
| 586 base::Thread cache_thread("CacheThread"); | 604 base::Thread cache_thread("CacheThread"); |
| 587 ASSERT_TRUE(cache_thread.StartWithOptions( | 605 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 588 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 606 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 589 | 607 |
| 590 uint32 flags = disk_cache::kNoBuffering; | 608 if (fast) |
| 591 if (!fast) | 609 AvoidTestFlag(); |
| 592 flags |= disk_cache::kNoRandom; | |
| 593 | 610 |
| 594 CreateBackend(flags, &cache_thread); | 611 CreateBackend(&cache_thread); |
| 612 SetNoBuffering(); |
| 595 | 613 |
| 596 disk_cache::Entry* entry; | 614 disk_cache::Entry* entry; |
| 597 int rv = cache_->CreateEntry("some key", &entry, cb.callback()); | 615 int rv = cache_->CreateEntry("some key", &entry, cb.callback()); |
| 598 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 616 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 599 | 617 |
| 600 entry->Close(); | 618 entry->Close(); |
| 601 | 619 |
| 602 // The cache destructor will see one pending operation here. | 620 // The cache destructor will see one pending operation here. |
| 603 cache_.reset(); | 621 cache_.reset(); |
| 604 } | 622 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 621 #endif | 639 #endif |
| 622 | 640 |
| 623 // Tests that we deal with create-type pending operations. | 641 // Tests that we deal with create-type pending operations. |
| 624 void DiskCacheBackendTest::BackendShutdownWithPendingCreate(bool fast) { | 642 void DiskCacheBackendTest::BackendShutdownWithPendingCreate(bool fast) { |
| 625 net::TestCompletionCallback cb; | 643 net::TestCompletionCallback cb; |
| 626 | 644 |
| 627 { | 645 { |
| 628 ASSERT_TRUE(CleanupCacheDir()); | 646 ASSERT_TRUE(CleanupCacheDir()); |
| 629 base::Thread cache_thread("CacheThread"); | 647 base::Thread cache_thread("CacheThread"); |
| 630 ASSERT_TRUE(cache_thread.StartWithOptions( | 648 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 631 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 649 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 632 | 650 |
| 633 disk_cache::BackendFlags flags = | 651 if (fast) |
| 634 fast ? disk_cache::kNone : disk_cache::kNoRandom; | 652 AvoidTestFlag(); |
| 635 CreateBackend(flags, &cache_thread); | 653 CreateBackend(&cache_thread); |
| 636 | 654 |
| 637 disk_cache::Entry* entry; | 655 disk_cache::Entry* entry; |
| 638 int rv = cache_->CreateEntry("some key", &entry, cb.callback()); | 656 int rv = cache_->CreateEntry("some key", &entry, cb.callback()); |
| 639 ASSERT_EQ(net::ERR_IO_PENDING, rv); | 657 ASSERT_EQ(net::ERR_IO_PENDING, rv); |
| 640 | 658 |
| 641 cache_.reset(); | 659 cache_.reset(); |
| 642 EXPECT_FALSE(cb.have_result()); | 660 EXPECT_FALSE(cb.have_result()); |
| 643 } | 661 } |
| 644 | 662 |
| 645 base::MessageLoop::current()->RunUntilIdle(); | 663 base::MessageLoop::current()->RunUntilIdle(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 659 } | 677 } |
| 660 #endif | 678 #endif |
| 661 | 679 |
| 662 TEST_F(DiskCacheTest, TruncatedIndex) { | 680 TEST_F(DiskCacheTest, TruncatedIndex) { |
| 663 ASSERT_TRUE(CleanupCacheDir()); | 681 ASSERT_TRUE(CleanupCacheDir()); |
| 664 base::FilePath index = cache_path_.AppendASCII("index"); | 682 base::FilePath index = cache_path_.AppendASCII("index"); |
| 665 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5)); | 683 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5)); |
| 666 | 684 |
| 667 base::Thread cache_thread("CacheThread"); | 685 base::Thread cache_thread("CacheThread"); |
| 668 ASSERT_TRUE(cache_thread.StartWithOptions( | 686 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 669 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 687 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 670 net::TestCompletionCallback cb; | 688 net::TestCompletionCallback cb; |
| 671 | 689 |
| 672 scoped_ptr<disk_cache::Backend> backend; | 690 scoped_ptr<disk_cache::Backend> backend; |
| 673 int rv = | 691 int rv = disk_cache::CreateCacheBackend( |
| 674 disk_cache::CreateCacheBackend(net::DISK_CACHE, | 692 net::DISK_CACHE, net::CACHE_BACKEND_BLOCKFILE, cache_path_, 0, false, |
| 675 net::CACHE_BACKEND_BLOCKFILE, | 693 cache_thread.message_loop_proxy(), NULL, &backend, cb.callback()); |
| 676 cache_path_, | |
| 677 0, | |
| 678 false, | |
| 679 cache_thread.message_loop_proxy().get(), | |
| 680 NULL, | |
| 681 &backend, | |
| 682 cb.callback()); | |
| 683 ASSERT_NE(net::OK, cb.GetResult(rv)); | 694 ASSERT_NE(net::OK, cb.GetResult(rv)); |
| 684 | 695 |
| 685 ASSERT_FALSE(backend); | 696 ASSERT_FALSE(backend); |
| 686 } | 697 } |
| 687 | 698 |
| 688 void DiskCacheBackendTest::BackendSetSize() { | 699 void DiskCacheBackendTest::BackendSetSize() { |
| 689 const int cache_size = 0x10000; // 64 kB | 700 const int cache_size = 0x10000; // 64 kB |
| 690 SetMaxSize(cache_size); | 701 SetMaxSize(cache_size); |
| 691 InitCache(); | 702 InitCache(); |
| 692 | 703 |
| 693 std::string first("some key"); | 704 std::string first("some key"); |
| 694 std::string second("something else"); | 705 std::string second("something else"); |
| 695 disk_cache::Entry* entry; | 706 disk_cache::Entry* entry; |
| 696 ASSERT_EQ(net::OK, CreateEntry(first, &entry)); | 707 ASSERT_EQ(net::OK, CreateEntry(first, &entry)); |
| 697 | 708 |
| 698 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(cache_size)); | 709 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(cache_size)); |
| 699 memset(buffer->data(), 0, cache_size); | 710 memset(buffer->data(), 0, cache_size); |
| 700 EXPECT_EQ(cache_size / 10, | 711 EXPECT_EQ(cache_size / 10, |
| 701 WriteData(entry, 0, 0, buffer.get(), cache_size / 10, false)) | 712 WriteData(entry, 0, 0, buffer.get(), cache_size / 10, false)) << |
| 702 << "normal file"; | 713 "normal file"; |
| 703 | 714 |
| 704 EXPECT_EQ(net::ERR_FAILED, | 715 EXPECT_EQ(net::ERR_FAILED, |
| 705 WriteData(entry, 1, 0, buffer.get(), cache_size / 5, false)) | 716 WriteData(entry, 1, 0, buffer.get(), cache_size / 5, false)) << |
| 706 << "file size above the limit"; | 717 "file size above the limit"; |
| 707 | 718 |
| 708 // By doubling the total size, we make this file cacheable. | 719 // By doubling the total size, we make this file cacheable. |
| 709 SetMaxSize(cache_size * 2); | 720 SetMaxSize(cache_size * 2); |
| 710 EXPECT_EQ(cache_size / 5, | 721 EXPECT_EQ(cache_size / 5, WriteData(entry, 1, 0, buffer.get(), cache_size / 5, |
| 711 WriteData(entry, 1, 0, buffer.get(), cache_size / 5, false)); | 722 false)); |
| 712 | 723 |
| 713 // Let's fill up the cache!. | 724 // Let's fill up the cache!. |
| 714 SetMaxSize(cache_size * 10); | 725 SetMaxSize(cache_size * 10); |
| 715 EXPECT_EQ(cache_size * 3 / 4, | 726 EXPECT_EQ(cache_size * 3 / 4, WriteData(entry, 0, 0, buffer.get(), |
| 716 WriteData(entry, 0, 0, buffer.get(), cache_size * 3 / 4, false)); | 727 cache_size * 3 / 4, false)); |
| 717 entry->Close(); | 728 entry->Close(); |
| 718 FlushQueueForTest(); | 729 FlushQueueForTest(); |
| 719 | 730 |
| 720 SetMaxSize(cache_size); | 731 SetMaxSize(cache_size); |
| 721 | 732 |
| 722 // The cache is 95% full. | 733 // The cache is 95% full. |
| 723 | 734 |
| 724 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); | 735 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); |
| 725 EXPECT_EQ(cache_size / 10, | 736 EXPECT_EQ(cache_size / 10, |
| 726 WriteData(entry, 0, 0, buffer.get(), cache_size / 10, false)); | 737 WriteData(entry, 0, 0, buffer.get(), cache_size / 10, false)); |
| 727 | 738 |
| 728 disk_cache::Entry* entry2; | 739 disk_cache::Entry* entry2; |
| 729 ASSERT_EQ(net::OK, CreateEntry("an extra key", &entry2)); | 740 std::string extra_key("an extra key"); |
| 730 EXPECT_EQ(cache_size / 10, | 741 ASSERT_EQ(net::OK, CreateEntry(extra_key, &entry2)); |
| 731 WriteData(entry2, 0, 0, buffer.get(), cache_size / 10, false)); | 742 EXPECT_EQ(cache_size / 10, WriteData(entry2, 0, 0, buffer.get(), |
| 743 cache_size / 10, false)); |
| 732 entry2->Close(); // This will trigger the cache trim. | 744 entry2->Close(); // This will trigger the cache trim. |
| 733 | 745 WaitForEntryToClose(extra_key); |
| 734 EXPECT_NE(net::OK, OpenEntry(first, &entry2)); | |
| 735 | 746 |
| 736 FlushQueueForTest(); // Make sure that we are done trimming the cache. | 747 FlushQueueForTest(); // Make sure that we are done trimming the cache. |
| 737 FlushQueueForTest(); // We may have posted two tasks to evict stuff. | 748 FlushQueueForTest(); // We may have posted two tasks to evict stuff. |
| 738 | 749 |
| 739 entry->Close(); | 750 entry->Close(); |
| 751 WaitForEntryToClose(second); |
| 752 |
| 753 EXPECT_NE(net::OK, OpenEntry(first, &entry2)); |
| 740 ASSERT_EQ(net::OK, OpenEntry(second, &entry)); | 754 ASSERT_EQ(net::OK, OpenEntry(second, &entry)); |
| 741 EXPECT_EQ(cache_size / 10, entry->GetDataSize(0)); | 755 EXPECT_EQ(cache_size / 10, entry->GetDataSize(0)); |
| 742 entry->Close(); | 756 entry->Close(); |
| 743 } | 757 } |
| 744 | 758 |
| 745 TEST_F(DiskCacheBackendTest, SetSize) { | 759 TEST_F(DiskCacheBackendTest, SetSize) { |
| 746 BackendSetSize(); | 760 BackendSetSize(); |
| 747 } | 761 } |
| 748 | 762 |
| 763 TEST_F(DiskCacheBackendTest, V3SetSize) { |
| 764 UseVersion3(); |
| 765 UseVersion3(); |
| 766 SetNewEviction(); |
| 767 BackendSetSize(); |
| 768 } |
| 769 |
| 749 TEST_F(DiskCacheBackendTest, NewEvictionSetSize) { | 770 TEST_F(DiskCacheBackendTest, NewEvictionSetSize) { |
| 750 SetNewEviction(); | 771 SetNewEviction(); |
| 751 BackendSetSize(); | 772 BackendSetSize(); |
| 752 } | 773 } |
| 753 | 774 |
| 775 TEST_F(DiskCacheBackendTest, V3NewEvictionSetSize) { |
| 776 UseVersion3(); |
| 777 SetNewEviction(); |
| 778 BackendSetSize(); |
| 779 } |
| 780 |
| 754 TEST_F(DiskCacheBackendTest, MemoryOnlySetSize) { | 781 TEST_F(DiskCacheBackendTest, MemoryOnlySetSize) { |
| 755 SetMemoryOnlyMode(); | 782 SetMemoryOnlyMode(); |
| 756 BackendSetSize(); | 783 BackendSetSize(); |
| 757 } | 784 } |
| 758 | 785 |
| 759 void DiskCacheBackendTest::BackendLoad() { | 786 void DiskCacheBackendTest::BackendLoad() { |
| 760 InitCache(); | 787 InitCache(); |
| 761 int seed = static_cast<int>(Time::Now().ToInternalValue()); | 788 int seed = static_cast<int>(Time::Now().ToInternalValue()); |
| 762 srand(seed); | 789 srand(seed); |
| 763 | 790 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 TEST_F(DiskCacheBackendTest, AppCacheChain) { | 877 TEST_F(DiskCacheBackendTest, AppCacheChain) { |
| 851 SetCacheType(net::APP_CACHE); | 878 SetCacheType(net::APP_CACHE); |
| 852 BackendChain(); | 879 BackendChain(); |
| 853 } | 880 } |
| 854 | 881 |
| 855 TEST_F(DiskCacheBackendTest, ShaderCacheChain) { | 882 TEST_F(DiskCacheBackendTest, ShaderCacheChain) { |
| 856 SetCacheType(net::SHADER_CACHE); | 883 SetCacheType(net::SHADER_CACHE); |
| 857 BackendChain(); | 884 BackendChain(); |
| 858 } | 885 } |
| 859 | 886 |
| 860 TEST_F(DiskCacheBackendTest, NewEvictionTrim) { | 887 // Tests the proper use of cell buckets while the index grow. |
| 888 void DiskCacheBackendTest::BucketUse() { |
| 889 UseVersion3(); |
| 890 InitCache(); |
| 891 const int kNumEntries = 20; |
| 892 disk_cache::Entry* entries[kNumEntries]; |
| 893 std::string key("The first key"); |
| 894 |
| 895 // This generates kNumEntries collisions so the extra table has to be used. |
| 896 // There are only 2 extra buckets on the test setup, so the index has to grow. |
| 897 for (int i = 0; i < kNumEntries; i++) { |
| 898 ASSERT_EQ(net::OK, CreateEntry(key, &entries[i])); |
| 899 entries[i]->Doom(); |
| 900 FlushQueueForTest(); |
| 901 } |
| 902 |
| 903 for (int i = 0; i < kNumEntries / 2; i++) |
| 904 entries[i]->Close(); |
| 905 |
| 906 for (int i = 0; i < kNumEntries / 2; i++) { |
| 907 ASSERT_EQ(net::OK, CreateEntry(key, &entries[i])); |
| 908 entries[i]->Doom(); |
| 909 } |
| 910 |
| 911 for (int i = 0; i < kNumEntries; i++) |
| 912 entries[i]->Close(); |
| 913 } |
| 914 |
| 915 TEST_F(DiskCacheBackendTest, V3BucketUse) { |
| 916 BucketUse(); |
| 917 } |
| 918 |
| 919 TEST_F(DiskCacheBackendTest, V3DoubleIndexBucketUse) { |
| 920 PresetTestMode(); // Doubles the index instead of a slow growth. |
| 921 BucketUse(); |
| 922 } |
| 923 |
| 924 TEST_F(DiskCacheBackendTest, V3DoubleIndex) { |
| 925 UseVersion3(); |
| 926 PresetTestMode(); |
| 927 InitCache(); |
| 928 |
| 929 disk_cache::Entry* entry; |
| 930 const int kNumEntries = 200; |
| 931 for (int i = 0; i < kNumEntries; i++) { |
| 932 std::string name(base::StringPrintf("Key %d", i)); |
| 933 ASSERT_EQ(net::OK, CreateEntry(name, &entry)); |
| 934 entry->Close(); |
| 935 FlushQueueForTest(); |
| 936 } |
| 937 |
| 938 // Generate enough collisions to force growing the extra table (and with it, |
| 939 // the index). |
| 940 const int kNumSavedEntries = 5; |
| 941 disk_cache::Entry* entries[kNumSavedEntries]; |
| 942 std::string key("The first key"); |
| 943 for (int i = 0; i < kNumSavedEntries; i++) { |
| 944 ASSERT_EQ(net::OK, CreateEntry(key, &entries[i])); |
| 945 entries[i]->Doom(); |
| 946 FlushQueueForTest(); |
| 947 } |
| 948 |
| 949 for (int i = 0; i < kNumSavedEntries; i++) |
| 950 entries[i]->Close(); |
| 951 |
| 952 // Verify that all entries are there. |
| 953 for (int i = 0; i < kNumEntries; i++) { |
| 954 std::string name(base::StringPrintf("Key %d", i)); |
| 955 ASSERT_EQ(net::OK, OpenEntry(name, &entry)); |
| 956 entry->Close(); |
| 957 } |
| 958 } |
| 959 |
| 960 // This test leaks memory because it simulates a crash. |
| 961 TEST_F(DiskCacheBackendTest, DISABLED_V3Backup) { |
| 962 UseVersion3(); |
| 963 PresetTestMode(); |
| 964 InitCache(); |
| 965 |
| 966 disk_cache::Entry* entry; |
| 967 std::string name1("First entry"); |
| 968 ASSERT_EQ(net::OK, CreateEntry(name1, &entry)); |
| 969 entry->Close(); |
| 970 WaitForEntryToClose(name1); |
| 971 |
| 972 std::string name2("Another entry"); |
| 973 ASSERT_EQ(net::OK, CreateEntry(name2, &entry)); |
| 974 |
| 975 SimulateCrash(); |
| 976 EXPECT_EQ(net::OK, OpenEntry(name1, &entry)); |
| 977 entry->Close(); |
| 978 EXPECT_NE(net::OK, OpenEntry(name2, &entry)); |
| 979 } |
| 980 |
| 981 void DiskCacheBackendTest::BackendNewEvictionTrim() { |
| 861 SetNewEviction(); | 982 SetNewEviction(); |
| 862 InitCache(); | 983 InitCache(); |
| 863 | 984 |
| 864 disk_cache::Entry* entry; | 985 disk_cache::Entry* entry; |
| 865 for (int i = 0; i < 100; i++) { | 986 for (int i = 0; i < 100; i++) { |
| 866 std::string name(base::StringPrintf("Key %d", i)); | 987 std::string name(base::StringPrintf("Key %d", i)); |
| 867 ASSERT_EQ(net::OK, CreateEntry(name, &entry)); | 988 ASSERT_EQ(net::OK, CreateEntry(name, &entry)); |
| 868 entry->Close(); | 989 entry->Close(); |
| 990 AddDelayForTest(kDelayToNextTimestamp); |
| 991 |
| 869 if (i < 90) { | 992 if (i < 90) { |
| 870 // Entries 0 to 89 are in list 1; 90 to 99 are in list 0. | 993 // Entries 0 to 89 are in list 1; 90 to 99 are in list 0. |
| 871 ASSERT_EQ(net::OK, OpenEntry(name, &entry)); | 994 ASSERT_EQ(net::OK, OpenEntry(name, &entry)); |
| 872 entry->Close(); | 995 entry->Close(); |
| 873 } | 996 } |
| 997 if (!(i % 10)) |
| 998 FlushQueueForTest(); |
| 999 |
| 1000 if (i == 0 || i == 90) |
| 1001 WaitForEntryToClose(name); |
| 874 } | 1002 } |
| 875 | 1003 |
| 876 // The first eviction must come from list 1 (10% limit), the second must come | 1004 // The first eviction must come from list 1 (10% limit), the second must come |
| 877 // from list 0. | 1005 // from list 0. |
| 878 TrimForTest(false); | 1006 TrimForTest(false); |
| 879 EXPECT_NE(net::OK, OpenEntry("Key 0", &entry)); | 1007 EXPECT_NE(net::OK, OpenEntry("Key 0", &entry)); |
| 880 TrimForTest(false); | 1008 TrimForTest(false); |
| 881 EXPECT_NE(net::OK, OpenEntry("Key 90", &entry)); | 1009 EXPECT_NE(net::OK, OpenEntry("Key 90", &entry)); |
| 882 | 1010 |
| 883 // Double check that we still have the list tails. | 1011 // Double check that we still have the list tails. |
| 884 ASSERT_EQ(net::OK, OpenEntry("Key 1", &entry)); | 1012 ASSERT_EQ(net::OK, OpenEntry("Key 1", &entry)); |
| 885 entry->Close(); | 1013 entry->Close(); |
| 886 ASSERT_EQ(net::OK, OpenEntry("Key 91", &entry)); | 1014 ASSERT_EQ(net::OK, OpenEntry("Key 91", &entry)); |
| 887 entry->Close(); | 1015 entry->Close(); |
| 888 } | 1016 } |
| 889 | 1017 |
| 1018 TEST_F(DiskCacheBackendTest, NewEvictionTrim) { |
| 1019 BackendNewEvictionTrim(); |
| 1020 } |
| 1021 |
| 1022 TEST_F(DiskCacheBackendTest, V3NewEvictionTrim) { |
| 1023 UseVersion3(); |
| 1024 BackendNewEvictionTrim(); |
| 1025 } |
| 1026 |
| 890 // Before looking for invalid entries, let's check a valid entry. | 1027 // Before looking for invalid entries, let's check a valid entry. |
| 891 void DiskCacheBackendTest::BackendValidEntry() { | 1028 void DiskCacheBackendTest::BackendValidEntry() { |
| 892 InitCache(); | 1029 InitCache(); |
| 893 | 1030 |
| 894 std::string key("Some key"); | 1031 std::string key("Some key"); |
| 895 disk_cache::Entry* entry; | 1032 disk_cache::Entry* entry; |
| 896 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1033 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
| 897 | 1034 |
| 898 const int kSize = 50; | 1035 const int kSize = 50; |
| 899 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); | 1036 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 void DiskCacheBackendTest::BackendEnumerations() { | 1347 void DiskCacheBackendTest::BackendEnumerations() { |
| 1211 InitCache(); | 1348 InitCache(); |
| 1212 Time initial = Time::Now(); | 1349 Time initial = Time::Now(); |
| 1213 | 1350 |
| 1214 const int kNumEntries = 100; | 1351 const int kNumEntries = 100; |
| 1215 for (int i = 0; i < kNumEntries; i++) { | 1352 for (int i = 0; i < kNumEntries; i++) { |
| 1216 std::string key = GenerateKey(true); | 1353 std::string key = GenerateKey(true); |
| 1217 disk_cache::Entry* entry; | 1354 disk_cache::Entry* entry; |
| 1218 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1355 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
| 1219 entry->Close(); | 1356 entry->Close(); |
| 1357 if (!(i % 10)) |
| 1358 FlushQueueForTest(); |
| 1220 } | 1359 } |
| 1221 EXPECT_EQ(kNumEntries, cache_->GetEntryCount()); | 1360 EXPECT_EQ(kNumEntries, cache_->GetEntryCount()); |
| 1222 Time final = Time::Now(); | 1361 Time final = Time::Now(); |
| 1223 | 1362 |
| 1224 disk_cache::Entry* entry; | 1363 disk_cache::Entry* entry; |
| 1225 void* iter = NULL; | 1364 void* iter = NULL; |
| 1226 int count = 0; | 1365 int count = 0; |
| 1227 Time last_modified[kNumEntries]; | 1366 Time last_modified[kNumEntries]; |
| 1228 Time last_used[kNumEntries]; | 1367 Time last_used[kNumEntries]; |
| 1229 while (OpenNextEntry(&iter, &entry) == net::OK) { | 1368 while (OpenNextEntry(&iter, &entry) == net::OK) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1252 entry->Close(); | 1391 entry->Close(); |
| 1253 count++; | 1392 count++; |
| 1254 }; | 1393 }; |
| 1255 EXPECT_EQ(kNumEntries, count); | 1394 EXPECT_EQ(kNumEntries, count); |
| 1256 } | 1395 } |
| 1257 | 1396 |
| 1258 TEST_F(DiskCacheBackendTest, Enumerations) { | 1397 TEST_F(DiskCacheBackendTest, Enumerations) { |
| 1259 BackendEnumerations(); | 1398 BackendEnumerations(); |
| 1260 } | 1399 } |
| 1261 | 1400 |
| 1401 TEST_F(DiskCacheBackendTest, V3Enumerations) { |
| 1402 UseVersion3(); |
| 1403 BackendEnumerations(); |
| 1404 } |
| 1405 |
| 1262 TEST_F(DiskCacheBackendTest, NewEvictionEnumerations) { | 1406 TEST_F(DiskCacheBackendTest, NewEvictionEnumerations) { |
| 1263 SetNewEviction(); | 1407 SetNewEviction(); |
| 1264 BackendEnumerations(); | 1408 BackendEnumerations(); |
| 1265 } | 1409 } |
| 1266 | 1410 |
| 1411 TEST_F(DiskCacheBackendTest, V3NewEvictionEnumerations) { |
| 1412 UseVersion3(); |
| 1413 SetNewEviction(); |
| 1414 BackendEnumerations(); |
| 1415 } |
| 1416 |
| 1267 TEST_F(DiskCacheBackendTest, MemoryOnlyEnumerations) { | 1417 TEST_F(DiskCacheBackendTest, MemoryOnlyEnumerations) { |
| 1268 SetMemoryOnlyMode(); | 1418 SetMemoryOnlyMode(); |
| 1269 BackendEnumerations(); | 1419 BackendEnumerations(); |
| 1270 } | 1420 } |
| 1271 | 1421 |
| 1272 TEST_F(DiskCacheBackendTest, ShaderCacheEnumerations) { | 1422 TEST_F(DiskCacheBackendTest, ShaderCacheEnumerations) { |
| 1273 SetCacheType(net::SHADER_CACHE); | 1423 SetCacheType(net::SHADER_CACHE); |
| 1274 BackendEnumerations(); | 1424 BackendEnumerations(); |
| 1275 } | 1425 } |
| 1276 | 1426 |
| 1277 TEST_F(DiskCacheBackendTest, AppCacheEnumerations) { | 1427 TEST_F(DiskCacheBackendTest, AppCacheEnumerations) { |
| 1278 SetCacheType(net::APP_CACHE); | 1428 SetCacheType(net::APP_CACHE); |
| 1279 BackendEnumerations(); | 1429 BackendEnumerations(); |
| 1280 } | 1430 } |
| 1281 | 1431 |
| 1282 // Verifies enumerations while entries are open. | 1432 // Verifies enumerations while entries are open. |
| 1283 void DiskCacheBackendTest::BackendEnumerations2() { | 1433 void DiskCacheBackendTest::BackendEnumerations2() { |
| 1284 InitCache(); | 1434 InitCache(); |
| 1285 const std::string first("first"); | 1435 const std::string first("first"); |
| 1286 const std::string second("second"); | 1436 const std::string second("second"); |
| 1287 disk_cache::Entry *entry1, *entry2; | 1437 disk_cache::Entry *entry1, *entry2; |
| 1288 ASSERT_EQ(net::OK, CreateEntry(first, &entry1)); | 1438 ASSERT_EQ(net::OK, CreateEntry(first, &entry1)); |
| 1289 entry1->Close(); | 1439 entry1->Close(); |
| 1290 ASSERT_EQ(net::OK, CreateEntry(second, &entry2)); | 1440 ASSERT_EQ(net::OK, CreateEntry(second, &entry2)); |
| 1291 entry2->Close(); | 1441 entry2->Close(); |
| 1292 FlushQueueForTest(); | 1442 FlushQueueForTest(); |
| 1293 | 1443 |
| 1294 // Make sure that the timestamp is not the same. | 1444 // Make sure that the timestamp is not the same. |
| 1295 AddDelay(); | 1445 AddDelayForTest(kDelayToNextTimestamp); |
| 1296 ASSERT_EQ(net::OK, OpenEntry(second, &entry1)); | 1446 ASSERT_EQ(net::OK, OpenEntry(second, &entry1)); |
| 1297 void* iter = NULL; | 1447 void* iter = NULL; |
| 1298 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2)); | 1448 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2)); |
| 1299 EXPECT_EQ(entry2->GetKey(), second); | 1449 EXPECT_EQ(entry2->GetKey(), second); |
| 1300 | 1450 |
| 1301 // Two entries and the iterator pointing at "first". | 1451 // Two entries and the iterator pointing at "first". |
| 1302 entry1->Close(); | 1452 entry1->Close(); |
| 1303 entry2->Close(); | 1453 entry2->Close(); |
| 1304 | 1454 |
| 1305 // The iterator should still be valid, so we should not crash. | 1455 // The iterator should still be valid, so we should not crash. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1321 | 1471 |
| 1322 entry1->Close(); | 1472 entry1->Close(); |
| 1323 entry2->Close(); | 1473 entry2->Close(); |
| 1324 cache_->EndEnumeration(&iter); | 1474 cache_->EndEnumeration(&iter); |
| 1325 } | 1475 } |
| 1326 | 1476 |
| 1327 TEST_F(DiskCacheBackendTest, Enumerations2) { | 1477 TEST_F(DiskCacheBackendTest, Enumerations2) { |
| 1328 BackendEnumerations2(); | 1478 BackendEnumerations2(); |
| 1329 } | 1479 } |
| 1330 | 1480 |
| 1481 TEST_F(DiskCacheBackendTest, V3Enumerations2) { |
| 1482 UseVersion3(); |
| 1483 BackendEnumerations2(); |
| 1484 } |
| 1485 |
| 1331 TEST_F(DiskCacheBackendTest, NewEvictionEnumerations2) { | 1486 TEST_F(DiskCacheBackendTest, NewEvictionEnumerations2) { |
| 1332 SetNewEviction(); | 1487 SetNewEviction(); |
| 1333 BackendEnumerations2(); | 1488 BackendEnumerations2(); |
| 1334 } | 1489 } |
| 1335 | 1490 |
| 1491 TEST_F(DiskCacheBackendTest, V3NewEvictionEnumerations2) { |
| 1492 UseVersion3(); |
| 1493 SetNewEviction(); |
| 1494 BackendEnumerations2(); |
| 1495 } |
| 1496 |
| 1336 TEST_F(DiskCacheBackendTest, MemoryOnlyEnumerations2) { | 1497 TEST_F(DiskCacheBackendTest, MemoryOnlyEnumerations2) { |
| 1337 SetMemoryOnlyMode(); | 1498 SetMemoryOnlyMode(); |
| 1338 BackendEnumerations2(); | 1499 BackendEnumerations2(); |
| 1339 } | 1500 } |
| 1340 | 1501 |
| 1341 TEST_F(DiskCacheBackendTest, AppCacheEnumerations2) { | 1502 TEST_F(DiskCacheBackendTest, AppCacheEnumerations2) { |
| 1342 SetCacheType(net::APP_CACHE); | 1503 SetCacheType(net::APP_CACHE); |
| 1343 BackendEnumerations2(); | 1504 BackendEnumerations2(); |
| 1344 } | 1505 } |
| 1345 | 1506 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1501 void DiskCacheBackendTest::BackendDoomRecent() { | 1662 void DiskCacheBackendTest::BackendDoomRecent() { |
| 1502 InitCache(); | 1663 InitCache(); |
| 1503 | 1664 |
| 1504 disk_cache::Entry *entry; | 1665 disk_cache::Entry *entry; |
| 1505 ASSERT_EQ(net::OK, CreateEntry("first", &entry)); | 1666 ASSERT_EQ(net::OK, CreateEntry("first", &entry)); |
| 1506 entry->Close(); | 1667 entry->Close(); |
| 1507 ASSERT_EQ(net::OK, CreateEntry("second", &entry)); | 1668 ASSERT_EQ(net::OK, CreateEntry("second", &entry)); |
| 1508 entry->Close(); | 1669 entry->Close(); |
| 1509 FlushQueueForTest(); | 1670 FlushQueueForTest(); |
| 1510 | 1671 |
| 1511 AddDelay(); | 1672 AddDelayForTest(kDelayToNextTimestamp); |
| 1512 Time middle = Time::Now(); | 1673 Time middle = GetCurrentTime(); |
| 1513 | 1674 |
| 1514 ASSERT_EQ(net::OK, CreateEntry("third", &entry)); | 1675 ASSERT_EQ(net::OK, CreateEntry("third", &entry)); |
| 1515 entry->Close(); | 1676 entry->Close(); |
| 1516 ASSERT_EQ(net::OK, CreateEntry("fourth", &entry)); | 1677 ASSERT_EQ(net::OK, CreateEntry("fourth", &entry)); |
| 1517 entry->Close(); | 1678 entry->Close(); |
| 1518 FlushQueueForTest(); | 1679 FlushQueueForTest(); |
| 1519 | 1680 |
| 1520 AddDelay(); | 1681 AddDelayForTest(kDelayToNextTimestamp); |
| 1521 Time final = Time::Now(); | 1682 Time final = GetCurrentTime(); |
| 1522 | 1683 |
| 1523 ASSERT_EQ(4, cache_->GetEntryCount()); | 1684 ASSERT_EQ(4, cache_->GetEntryCount()); |
| 1524 EXPECT_EQ(net::OK, DoomEntriesSince(final)); | 1685 EXPECT_EQ(net::OK, DoomEntriesSince(final)); |
| 1525 ASSERT_EQ(4, cache_->GetEntryCount()); | 1686 ASSERT_EQ(4, cache_->GetEntryCount()); |
| 1526 | 1687 |
| 1527 EXPECT_EQ(net::OK, DoomEntriesSince(middle)); | 1688 EXPECT_EQ(net::OK, DoomEntriesSince(middle)); |
| 1528 ASSERT_EQ(2, cache_->GetEntryCount()); | 1689 ASSERT_EQ(2, cache_->GetEntryCount()); |
| 1529 | 1690 |
| 1530 ASSERT_EQ(net::OK, OpenEntry("second", &entry)); | 1691 ASSERT_EQ(net::OK, OpenEntry("second", &entry)); |
| 1531 entry->Close(); | 1692 entry->Close(); |
| 1532 } | 1693 } |
| 1533 | 1694 |
| 1534 TEST_F(DiskCacheBackendTest, DoomRecent) { | 1695 TEST_F(DiskCacheBackendTest, DoomRecent) { |
| 1535 BackendDoomRecent(); | 1696 BackendDoomRecent(); |
| 1536 } | 1697 } |
| 1537 | 1698 |
| 1699 TEST_F(DiskCacheBackendTest, V3DoomRecent) { |
| 1700 UseVersion3(); |
| 1701 BackendDoomRecent(); |
| 1702 } |
| 1703 |
| 1538 TEST_F(DiskCacheBackendTest, NewEvictionDoomRecent) { | 1704 TEST_F(DiskCacheBackendTest, NewEvictionDoomRecent) { |
| 1539 SetNewEviction(); | 1705 SetNewEviction(); |
| 1540 BackendDoomRecent(); | 1706 BackendDoomRecent(); |
| 1541 } | 1707 } |
| 1542 | 1708 |
| 1709 TEST_F(DiskCacheBackendTest, V3NewEvictionDoomRecent) { |
| 1710 UseVersion3(); |
| 1711 SetNewEviction(); |
| 1712 BackendDoomRecent(); |
| 1713 } |
| 1714 |
| 1543 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomRecent) { | 1715 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomRecent) { |
| 1544 SetMemoryOnlyMode(); | 1716 SetMemoryOnlyMode(); |
| 1545 BackendDoomRecent(); | 1717 BackendDoomRecent(); |
| 1546 } | 1718 } |
| 1547 | 1719 |
| 1548 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomEntriesSinceSparse) { | 1720 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomEntriesSinceSparse) { |
| 1549 SetMemoryOnlyMode(); | 1721 SetMemoryOnlyMode(); |
| 1550 base::Time start; | 1722 base::Time start; |
| 1551 InitSparseCache(&start, NULL); | 1723 InitSparseCache(&start, NULL); |
| 1552 DoomEntriesSince(start); | 1724 DoomEntriesSince(start); |
| 1553 EXPECT_EQ(1, cache_->GetEntryCount()); | 1725 EXPECT_EQ(1, cache_->GetEntryCount()); |
| 1554 } | 1726 } |
| 1555 | 1727 |
| 1556 TEST_F(DiskCacheBackendTest, DoomEntriesSinceSparse) { | 1728 TEST_F(DiskCacheBackendTest, DoomEntriesSinceSparse) { |
| 1557 base::Time start; | 1729 base::Time start; |
| 1558 InitSparseCache(&start, NULL); | 1730 InitSparseCache(&start, NULL); |
| 1559 DoomEntriesSince(start); | 1731 DoomEntriesSince(start); |
| 1560 // NOTE: BackendImpl counts child entries in its GetEntryCount(), while | 1732 // NOTE: BackendImpl counts child entries in its GetEntryCount(), while |
| 1561 // MemBackendImpl does not. Thats why expected value differs here from | 1733 // MemBackendImpl does not. Thats why expected value differs here from |
| 1562 // MemoryOnlyDoomEntriesSinceSparse. | 1734 // MemoryOnlyDoomEntriesSinceSparse. |
| 1563 EXPECT_EQ(3, cache_->GetEntryCount()); | 1735 EXPECT_EQ(3, cache_->GetEntryCount()); |
| 1564 } | 1736 } |
| 1565 | 1737 |
| 1738 TEST_F(DiskCacheBackendTest, V3DoomEntriesSinceSparse) { |
| 1739 base::Time start; |
| 1740 UseVersion3(); |
| 1741 InitSparseCache(&start, NULL); |
| 1742 DoomEntriesSince(start); |
| 1743 // NOTE: BackendImpl counts child entries in its GetEntryCount(), while |
| 1744 // MemBackendImpl does not. Thats why expected value differs here from |
| 1745 // MemoryOnlyDoomEntriesSinceSparse. |
| 1746 EXPECT_EQ(3, cache_->GetEntryCount()); |
| 1747 } |
| 1748 |
| 1566 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAllSparse) { | 1749 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAllSparse) { |
| 1567 SetMemoryOnlyMode(); | 1750 SetMemoryOnlyMode(); |
| 1568 InitSparseCache(NULL, NULL); | 1751 InitSparseCache(NULL, NULL); |
| 1569 EXPECT_EQ(net::OK, DoomAllEntries()); | 1752 EXPECT_EQ(net::OK, DoomAllEntries()); |
| 1570 EXPECT_EQ(0, cache_->GetEntryCount()); | 1753 EXPECT_EQ(0, cache_->GetEntryCount()); |
| 1571 } | 1754 } |
| 1572 | 1755 |
| 1573 TEST_F(DiskCacheBackendTest, DoomAllSparse) { | 1756 TEST_F(DiskCacheBackendTest, DoomAllSparse) { |
| 1574 InitSparseCache(NULL, NULL); | 1757 InitSparseCache(NULL, NULL); |
| 1575 EXPECT_EQ(net::OK, DoomAllEntries()); | 1758 EXPECT_EQ(net::OK, DoomAllEntries()); |
| 1576 EXPECT_EQ(0, cache_->GetEntryCount()); | 1759 EXPECT_EQ(0, cache_->GetEntryCount()); |
| 1577 } | 1760 } |
| 1578 | 1761 |
| 1762 TEST_F(DiskCacheBackendTest, V3DoomAllSparse) { |
| 1763 UseVersion3(); |
| 1764 InitSparseCache(NULL, NULL); |
| 1765 EXPECT_EQ(net::OK, DoomAllEntries()); |
| 1766 EXPECT_EQ(0, cache_->GetEntryCount()); |
| 1767 } |
| 1768 |
| 1579 void DiskCacheBackendTest::BackendDoomBetween() { | 1769 void DiskCacheBackendTest::BackendDoomBetween() { |
| 1580 InitCache(); | 1770 InitCache(); |
| 1581 | 1771 |
| 1582 disk_cache::Entry *entry; | 1772 disk_cache::Entry *entry; |
| 1583 ASSERT_EQ(net::OK, CreateEntry("first", &entry)); | 1773 ASSERT_EQ(net::OK, CreateEntry("first", &entry)); |
| 1584 entry->Close(); | 1774 entry->Close(); |
| 1585 FlushQueueForTest(); | 1775 FlushQueueForTest(); |
| 1586 | 1776 |
| 1587 AddDelay(); | 1777 AddDelay(); |
| 1588 Time middle_start = Time::Now(); | 1778 Time middle_start = Time::Now(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1617 ASSERT_EQ(1, cache_->GetEntryCount()); | 1807 ASSERT_EQ(1, cache_->GetEntryCount()); |
| 1618 | 1808 |
| 1619 ASSERT_EQ(net::OK, OpenEntry("first", &entry)); | 1809 ASSERT_EQ(net::OK, OpenEntry("first", &entry)); |
| 1620 entry->Close(); | 1810 entry->Close(); |
| 1621 } | 1811 } |
| 1622 | 1812 |
| 1623 TEST_F(DiskCacheBackendTest, DoomBetween) { | 1813 TEST_F(DiskCacheBackendTest, DoomBetween) { |
| 1624 BackendDoomBetween(); | 1814 BackendDoomBetween(); |
| 1625 } | 1815 } |
| 1626 | 1816 |
| 1817 TEST_F(DiskCacheBackendTest, V3DoomBetween) { |
| 1818 UseVersion3(); |
| 1819 BackendDoomBetween(); |
| 1820 } |
| 1821 |
| 1627 TEST_F(DiskCacheBackendTest, NewEvictionDoomBetween) { | 1822 TEST_F(DiskCacheBackendTest, NewEvictionDoomBetween) { |
| 1628 SetNewEviction(); | 1823 SetNewEviction(); |
| 1629 BackendDoomBetween(); | 1824 BackendDoomBetween(); |
| 1630 } | 1825 } |
| 1631 | 1826 |
| 1827 TEST_F(DiskCacheBackendTest, V3NewEvictionDoomBetween) { |
| 1828 UseVersion3(); |
| 1829 SetNewEviction(); |
| 1830 BackendDoomBetween(); |
| 1831 } |
| 1832 |
| 1632 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomBetween) { | 1833 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomBetween) { |
| 1633 SetMemoryOnlyMode(); | 1834 SetMemoryOnlyMode(); |
| 1634 BackendDoomBetween(); | 1835 BackendDoomBetween(); |
| 1635 } | 1836 } |
| 1636 | 1837 |
| 1637 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomEntriesBetweenSparse) { | 1838 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomEntriesBetweenSparse) { |
| 1638 SetMemoryOnlyMode(); | 1839 SetMemoryOnlyMode(); |
| 1639 base::Time start, end; | 1840 base::Time start, end; |
| 1640 InitSparseCache(&start, &end); | 1841 InitSparseCache(&start, &end); |
| 1641 DoomEntriesBetween(start, end); | 1842 DoomEntriesBetween(start, end); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1652 InitSparseCache(&start, &end); | 1853 InitSparseCache(&start, &end); |
| 1653 DoomEntriesBetween(start, end); | 1854 DoomEntriesBetween(start, end); |
| 1654 EXPECT_EQ(9, cache_->GetEntryCount()); | 1855 EXPECT_EQ(9, cache_->GetEntryCount()); |
| 1655 | 1856 |
| 1656 start = end; | 1857 start = end; |
| 1657 end = base::Time::Now(); | 1858 end = base::Time::Now(); |
| 1658 DoomEntriesBetween(start, end); | 1859 DoomEntriesBetween(start, end); |
| 1659 EXPECT_EQ(3, cache_->GetEntryCount()); | 1860 EXPECT_EQ(3, cache_->GetEntryCount()); |
| 1660 } | 1861 } |
| 1661 | 1862 |
| 1863 TEST_F(DiskCacheBackendTest, V3DoomEntriesBetweenSparse) { |
| 1864 base::Time start, end; |
| 1865 UseVersion3(); |
| 1866 InitSparseCache(&start, &end); |
| 1867 DoomEntriesBetween(start, end); |
| 1868 EXPECT_EQ(9, cache_->GetEntryCount()); |
| 1869 |
| 1870 start = end; |
| 1871 end = base::Time::Now(); |
| 1872 DoomEntriesBetween(start, end); |
| 1873 EXPECT_EQ(3, cache_->GetEntryCount()); |
| 1874 } |
| 1875 |
| 1662 void DiskCacheBackendTest::BackendTransaction(const std::string& name, | 1876 void DiskCacheBackendTest::BackendTransaction(const std::string& name, |
| 1663 int num_entries, bool load) { | 1877 int num_entries, bool load) { |
| 1664 success_ = false; | 1878 success_ = false; |
| 1665 ASSERT_TRUE(CopyTestCache(name)); | 1879 ASSERT_TRUE(CopyTestCache(name)); |
| 1666 DisableFirstCleanup(); | 1880 DisableFirstCleanup(); |
| 1667 | 1881 |
| 1668 uint32 mask; | 1882 uint32 mask; |
| 1669 if (load) { | 1883 if (load) { |
| 1670 mask = 0xf; | 1884 mask = 0xf; |
| 1671 SetMaxSize(0x100000); | 1885 SetMaxSize(0x100000); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1800 TEST_F(DiskCacheBackendTest, NewEvictionRecoverWithEviction) { | 2014 TEST_F(DiskCacheBackendTest, NewEvictionRecoverWithEviction) { |
| 1801 SetNewEviction(); | 2015 SetNewEviction(); |
| 1802 BackendRecoverWithEviction(); | 2016 BackendRecoverWithEviction(); |
| 1803 } | 2017 } |
| 1804 | 2018 |
| 1805 // Tests that the |BackendImpl| fails to start with the wrong cache version. | 2019 // Tests that the |BackendImpl| fails to start with the wrong cache version. |
| 1806 TEST_F(DiskCacheTest, WrongVersion) { | 2020 TEST_F(DiskCacheTest, WrongVersion) { |
| 1807 ASSERT_TRUE(CopyTestCache("wrong_version")); | 2021 ASSERT_TRUE(CopyTestCache("wrong_version")); |
| 1808 base::Thread cache_thread("CacheThread"); | 2022 base::Thread cache_thread("CacheThread"); |
| 1809 ASSERT_TRUE(cache_thread.StartWithOptions( | 2023 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 1810 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 2024 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 1811 net::TestCompletionCallback cb; | 2025 net::TestCompletionCallback cb; |
| 1812 | 2026 |
| 1813 scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( | 2027 scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl( |
| 1814 cache_path_, cache_thread.message_loop_proxy().get(), NULL)); | 2028 cache_path_, cache_thread.message_loop_proxy().get(), NULL)); |
| 1815 int rv = cache->Init(cb.callback()); | 2029 int rv = cache->Init(cb.callback()); |
| 1816 ASSERT_EQ(net::ERR_FAILED, cb.GetResult(rv)); | 2030 ASSERT_EQ(net::ERR_FAILED, cb.GetResult(rv)); |
| 1817 } | 2031 } |
| 1818 | 2032 |
| 1819 class BadEntropyProvider : public base::FieldTrial::EntropyProvider { | 2033 class BadEntropyProvider : public base::FieldTrial::EntropyProvider { |
| 1820 public: | 2034 public: |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1934 entry->Close(); | 2148 entry->Close(); |
| 1935 } | 2149 } |
| 1936 } | 2150 } |
| 1937 | 2151 |
| 1938 // Tests that the cache is properly restarted on recovery error. | 2152 // Tests that the cache is properly restarted on recovery error. |
| 1939 TEST_F(DiskCacheBackendTest, DeleteOld) { | 2153 TEST_F(DiskCacheBackendTest, DeleteOld) { |
| 1940 ASSERT_TRUE(CopyTestCache("wrong_version")); | 2154 ASSERT_TRUE(CopyTestCache("wrong_version")); |
| 1941 SetNewEviction(); | 2155 SetNewEviction(); |
| 1942 base::Thread cache_thread("CacheThread"); | 2156 base::Thread cache_thread("CacheThread"); |
| 1943 ASSERT_TRUE(cache_thread.StartWithOptions( | 2157 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 1944 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 2158 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 1945 | 2159 |
| 1946 net::TestCompletionCallback cb; | 2160 net::TestCompletionCallback cb; |
| 1947 bool prev = base::ThreadRestrictions::SetIOAllowed(false); | 2161 bool prev = base::ThreadRestrictions::SetIOAllowed(false); |
| 1948 base::FilePath path(cache_path_); | 2162 base::FilePath path(cache_path_); |
| 1949 int rv = | 2163 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, |
| 1950 disk_cache::CreateCacheBackend(net::DISK_CACHE, | 2164 net::CACHE_BACKEND_BLOCKFILE, path, |
| 1951 net::CACHE_BACKEND_BLOCKFILE, | 2165 0, true, |
| 1952 path, | 2166 cache_thread.message_loop_proxy(), |
| 1953 0, | 2167 NULL, &cache_, cb.callback()); |
| 1954 true, | |
| 1955 cache_thread.message_loop_proxy().get(), | |
| 1956 NULL, | |
| 1957 &cache_, | |
| 1958 cb.callback()); | |
| 1959 path.clear(); // Make sure path was captured by the previous call. | 2168 path.clear(); // Make sure path was captured by the previous call. |
| 1960 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 2169 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 1961 base::ThreadRestrictions::SetIOAllowed(prev); | 2170 base::ThreadRestrictions::SetIOAllowed(prev); |
| 1962 cache_.reset(); | 2171 cache_.reset(); |
| 1963 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_)); | 2172 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_)); |
| 1964 } | 2173 } |
| 1965 | 2174 |
| 1966 // We want to be able to deal with messed up entries on disk. | 2175 // We want to be able to deal with messed up entries on disk. |
| 1967 void DiskCacheBackendTest::BackendInvalidEntry2() { | 2176 void DiskCacheBackendTest::BackendInvalidEntry2() { |
| 1968 ASSERT_TRUE(CopyTestCache("bad_entry")); | 2177 ASSERT_TRUE(CopyTestCache("bad_entry")); |
| (...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2704 InitCache(); | 2913 InitCache(); |
| 2705 BackendDisable4(); | 2914 BackendDisable4(); |
| 2706 } | 2915 } |
| 2707 | 2916 |
| 2708 TEST_F(DiskCacheTest, Backend_UsageStatsTimer) { | 2917 TEST_F(DiskCacheTest, Backend_UsageStatsTimer) { |
| 2709 MessageLoopHelper helper; | 2918 MessageLoopHelper helper; |
| 2710 | 2919 |
| 2711 ASSERT_TRUE(CleanupCacheDir()); | 2920 ASSERT_TRUE(CleanupCacheDir()); |
| 2712 scoped_ptr<disk_cache::BackendImpl> cache; | 2921 scoped_ptr<disk_cache::BackendImpl> cache; |
| 2713 cache.reset(new disk_cache::BackendImpl( | 2922 cache.reset(new disk_cache::BackendImpl( |
| 2714 cache_path_, base::MessageLoopProxy::current().get(), NULL)); | 2923 cache_path_, base::MessageLoopProxy::current(), |
| 2924 NULL)); |
| 2715 ASSERT_TRUE(NULL != cache.get()); | 2925 ASSERT_TRUE(NULL != cache.get()); |
| 2716 cache->SetUnitTestMode(); | 2926 cache->SetUnitTestMode(); |
| 2717 ASSERT_EQ(net::OK, cache->SyncInit()); | 2927 ASSERT_EQ(net::OK, cache->SyncInit()); |
| 2718 | 2928 |
| 2719 // Wait for a callback that never comes... about 2 secs :). The message loop | 2929 // Wait for a callback that never comes... about 2 secs :). The message loop |
| 2720 // has to run to allow invocation of the usage timer. | 2930 // has to run to allow invocation of the usage timer. |
| 2721 helper.WaitUntilCacheIoFinished(1); | 2931 helper.WaitUntilCacheIoFinished(1); |
| 2722 } | 2932 } |
| 2723 | 2933 |
| 2724 TEST_F(DiskCacheBackendTest, Backend_UsageStats) { | 2934 TEST_F(DiskCacheBackendTest, Backend_UsageStats) { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2792 EXPECT_EQ(net::OK, DoomAllEntries()); | 3002 EXPECT_EQ(net::OK, DoomAllEntries()); |
| 2793 ASSERT_EQ(0, cache_->GetEntryCount()); | 3003 ASSERT_EQ(0, cache_->GetEntryCount()); |
| 2794 | 3004 |
| 2795 EXPECT_EQ(net::OK, DoomAllEntries()); | 3005 EXPECT_EQ(net::OK, DoomAllEntries()); |
| 2796 } | 3006 } |
| 2797 | 3007 |
| 2798 TEST_F(DiskCacheBackendTest, DoomAll) { | 3008 TEST_F(DiskCacheBackendTest, DoomAll) { |
| 2799 BackendDoomAll(); | 3009 BackendDoomAll(); |
| 2800 } | 3010 } |
| 2801 | 3011 |
| 3012 TEST_F(DiskCacheBackendTest, V3DoomAll) { |
| 3013 UseVersion3(); |
| 3014 BackendDoomAll(); |
| 3015 } |
| 3016 |
| 2802 TEST_F(DiskCacheBackendTest, NewEvictionDoomAll) { | 3017 TEST_F(DiskCacheBackendTest, NewEvictionDoomAll) { |
| 2803 SetNewEviction(); | 3018 SetNewEviction(); |
| 2804 BackendDoomAll(); | 3019 BackendDoomAll(); |
| 2805 } | 3020 } |
| 2806 | 3021 |
| 3022 TEST_F(DiskCacheBackendTest, V3NewEvictionDoomAll) { |
| 3023 UseVersion3(); |
| 3024 SetNewEviction(); |
| 3025 BackendDoomAll(); |
| 3026 } |
| 3027 |
| 2807 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) { | 3028 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomAll) { |
| 2808 SetMemoryOnlyMode(); | 3029 SetMemoryOnlyMode(); |
| 2809 BackendDoomAll(); | 3030 BackendDoomAll(); |
| 2810 } | 3031 } |
| 2811 | 3032 |
| 2812 TEST_F(DiskCacheBackendTest, AppCacheOnlyDoomAll) { | 3033 TEST_F(DiskCacheBackendTest, AppCacheOnlyDoomAll) { |
| 2813 SetCacheType(net::APP_CACHE); | 3034 SetCacheType(net::APP_CACHE); |
| 2814 BackendDoomAll(); | 3035 BackendDoomAll(); |
| 2815 } | 3036 } |
| 2816 | 3037 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2856 ASSERT_TRUE(store2.CreateUniqueTempDir()); | 3077 ASSERT_TRUE(store2.CreateUniqueTempDir()); |
| 2857 | 3078 |
| 2858 base::Thread cache_thread("CacheThread"); | 3079 base::Thread cache_thread("CacheThread"); |
| 2859 ASSERT_TRUE(cache_thread.StartWithOptions( | 3080 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 2860 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 3081 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
| 2861 net::TestCompletionCallback cb; | 3082 net::TestCompletionCallback cb; |
| 2862 | 3083 |
| 2863 const int kNumberOfCaches = 2; | 3084 const int kNumberOfCaches = 2; |
| 2864 scoped_ptr<disk_cache::Backend> cache[kNumberOfCaches]; | 3085 scoped_ptr<disk_cache::Backend> cache[kNumberOfCaches]; |
| 2865 | 3086 |
| 2866 int rv = | 3087 int rv = disk_cache::CreateCacheBackend( |
| 2867 disk_cache::CreateCacheBackend(net::DISK_CACHE, | 3088 net::DISK_CACHE, net::CACHE_BACKEND_DEFAULT, store1.path(), 0, false, |
| 2868 net::CACHE_BACKEND_DEFAULT, | 3089 cache_thread.message_loop_proxy(), NULL, &cache[0], cb.callback()); |
| 2869 store1.path(), | |
| 2870 0, | |
| 2871 false, | |
| 2872 cache_thread.message_loop_proxy().get(), | |
| 2873 NULL, | |
| 2874 &cache[0], | |
| 2875 cb.callback()); | |
| 2876 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 3090 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 2877 rv = disk_cache::CreateCacheBackend(net::MEDIA_CACHE, | 3091 rv = disk_cache::CreateCacheBackend( |
| 2878 net::CACHE_BACKEND_DEFAULT, | 3092 net::MEDIA_CACHE, net::CACHE_BACKEND_DEFAULT, store2.path(), 0, false, |
| 2879 store2.path(), | 3093 cache_thread.message_loop_proxy(), NULL, &cache[1], cb.callback()); |
| 2880 0, | |
| 2881 false, | |
| 2882 cache_thread.message_loop_proxy().get(), | |
| 2883 NULL, | |
| 2884 &cache[1], | |
| 2885 cb.callback()); | |
| 2886 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 3094 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 2887 | 3095 |
| 2888 ASSERT_TRUE(cache[0].get() != NULL && cache[1].get() != NULL); | 3096 ASSERT_TRUE(cache[0].get() != NULL && cache[1].get() != NULL); |
| 2889 | 3097 |
| 2890 std::string key("the first key"); | 3098 std::string key("the first key"); |
| 2891 disk_cache::Entry* entry; | 3099 disk_cache::Entry* entry; |
| 2892 for (int i = 0; i < kNumberOfCaches; i++) { | 3100 for (int i = 0; i < kNumberOfCaches; i++) { |
| 2893 rv = cache[i]->CreateEntry(key, &entry, cb.callback()); | 3101 rv = cache[i]->CreateEntry(key, &entry, cb.callback()); |
| 2894 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 3102 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 2895 entry->Close(); | 3103 entry->Close(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2951 InitCache(); | 3159 InitCache(); |
| 2952 disk_cache::BackendImpl* backend_ = cache_impl_; // Needed be the macro. | 3160 disk_cache::BackendImpl* backend_ = cache_impl_; // Needed be the macro. |
| 2953 | 3161 |
| 2954 for (int i = 1; i < 3; i++) { | 3162 for (int i = 1; i < 3; i++) { |
| 2955 CACHE_UMA(HOURS, "FillupTime", i, 28); | 3163 CACHE_UMA(HOURS, "FillupTime", i, 28); |
| 2956 } | 3164 } |
| 2957 } | 3165 } |
| 2958 | 3166 |
| 2959 // Make sure that we keep the total memory used by the internal buffers under | 3167 // Make sure that we keep the total memory used by the internal buffers under |
| 2960 // control. | 3168 // control. |
| 2961 TEST_F(DiskCacheBackendTest, TotalBuffersSize1) { | 3169 void DiskCacheBackendTest::BackendTotalBuffersSize1() { |
| 2962 InitCache(); | 3170 InitCache(); |
| 2963 std::string key("the first key"); | 3171 std::string key("the first key"); |
| 2964 disk_cache::Entry* entry; | 3172 disk_cache::Entry* entry; |
| 2965 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 3173 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
| 2966 | 3174 |
| 2967 const int kSize = 200; | 3175 const int kSize = 200; |
| 2968 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); | 3176 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); |
| 2969 CacheTestFillBuffer(buffer->data(), kSize, true); | 3177 CacheTestFillBuffer(buffer->data(), kSize, true); |
| 2970 | 3178 |
| 2971 for (int i = 0; i < 10; i++) { | 3179 for (int i = 0; i < 10; i++) { |
| 2972 SCOPED_TRACE(i); | 3180 SCOPED_TRACE(i); |
| 2973 // Allocate 2MB for this entry. | 3181 // Allocate 2MB for this entry. |
| 2974 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer.get(), kSize, true)); | 3182 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer.get(), kSize, true)); |
| 2975 EXPECT_EQ(kSize, WriteData(entry, 1, 0, buffer.get(), kSize, true)); | 3183 EXPECT_EQ(kSize, WriteData(entry, 1, 0, buffer.get(), kSize, true)); |
| 2976 EXPECT_EQ(kSize, | 3184 EXPECT_EQ(kSize, |
| 2977 WriteData(entry, 0, 1024 * 1024, buffer.get(), kSize, false)); | 3185 WriteData(entry, 0, 1024 * 1024, buffer.get(), kSize, false)); |
| 2978 EXPECT_EQ(kSize, | 3186 EXPECT_EQ(kSize, |
| 2979 WriteData(entry, 1, 1024 * 1024, buffer.get(), kSize, false)); | 3187 WriteData(entry, 1, 1024 * 1024, buffer.get(), kSize, false)); |
| 2980 | 3188 |
| 2981 // Delete one of the buffers and truncate the other. | 3189 // Delete one of the buffers and truncate the other. |
| 2982 EXPECT_EQ(0, WriteData(entry, 0, 0, buffer.get(), 0, true)); | 3190 EXPECT_EQ(0, WriteData(entry, 0, 0, buffer.get(), 0, true)); |
| 2983 EXPECT_EQ(0, WriteData(entry, 1, 10, buffer.get(), 0, true)); | 3191 EXPECT_EQ(0, WriteData(entry, 1, 10, buffer.get(), 0, true)); |
| 2984 | 3192 |
| 2985 // Delete the second buffer, writing 10 bytes to disk. | 3193 // Delete the second buffer, writing 10 bytes to disk. |
| 2986 entry->Close(); | 3194 entry->Close(); |
| 2987 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); | 3195 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); |
| 2988 } | 3196 } |
| 2989 | 3197 |
| 2990 entry->Close(); | 3198 entry->Close(); |
| 2991 EXPECT_EQ(0, cache_impl_->GetTotalBuffersSize()); | 3199 EXPECT_EQ(0, GetTotalBuffersSize()); |
| 3200 } |
| 3201 |
| 3202 TEST_F(DiskCacheBackendTest, TotalBuffersSize1) { |
| 3203 BackendTotalBuffersSize1(); |
| 3204 } |
| 3205 |
| 3206 TEST_F(DiskCacheBackendTest, V3TotalBuffersSize1) { |
| 3207 UseVersion3(); |
| 3208 BackendTotalBuffersSize1(); |
| 2992 } | 3209 } |
| 2993 | 3210 |
| 2994 // This test assumes at least 150MB of system memory. | 3211 // This test assumes at least 150MB of system memory. |
| 2995 TEST_F(DiskCacheBackendTest, TotalBuffersSize2) { | 3212 void DiskCacheBackendTest::BackendTotalBuffersSize2() { |
| 2996 InitCache(); | 3213 InitCache(); |
| 2997 | 3214 |
| 2998 const int kOneMB = 1024 * 1024; | 3215 const int kOneMB = 1024 * 1024; |
| 2999 EXPECT_TRUE(cache_impl_->IsAllocAllowed(0, kOneMB)); | 3216 EXPECT_TRUE(IsAllocAllowed(0, kOneMB)); |
| 3000 EXPECT_EQ(kOneMB, cache_impl_->GetTotalBuffersSize()); | 3217 EXPECT_EQ(kOneMB, GetTotalBuffersSize()); |
| 3001 | 3218 |
| 3002 EXPECT_TRUE(cache_impl_->IsAllocAllowed(0, kOneMB)); | 3219 EXPECT_TRUE(IsAllocAllowed(0, kOneMB)); |
| 3003 EXPECT_EQ(kOneMB * 2, cache_impl_->GetTotalBuffersSize()); | 3220 EXPECT_EQ(kOneMB * 2, GetTotalBuffersSize()); |
| 3004 | 3221 |
| 3005 EXPECT_TRUE(cache_impl_->IsAllocAllowed(0, kOneMB)); | 3222 EXPECT_TRUE(IsAllocAllowed(0, kOneMB)); |
| 3006 EXPECT_EQ(kOneMB * 3, cache_impl_->GetTotalBuffersSize()); | 3223 EXPECT_EQ(kOneMB * 3, GetTotalBuffersSize()); |
| 3007 | 3224 |
| 3008 cache_impl_->BufferDeleted(kOneMB); | 3225 BufferDeleted(kOneMB); |
| 3009 EXPECT_EQ(kOneMB * 2, cache_impl_->GetTotalBuffersSize()); | 3226 EXPECT_EQ(kOneMB * 2, GetTotalBuffersSize()); |
| 3010 | 3227 |
| 3011 // Check the upper limit. | 3228 // Check the upper limit. |
| 3012 EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, 30 * kOneMB)); | 3229 EXPECT_FALSE(IsAllocAllowed(0, 30 * kOneMB)); |
| 3013 | 3230 |
| 3014 for (int i = 0; i < 30; i++) | 3231 for (int i = 0; i < 30; i++) |
| 3015 cache_impl_->IsAllocAllowed(0, kOneMB); // Ignore the result. | 3232 IsAllocAllowed(0, kOneMB); // Ignore the result. |
| 3016 | 3233 |
| 3017 EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, kOneMB)); | 3234 EXPECT_FALSE(IsAllocAllowed(0, kOneMB)); |
| 3235 } |
| 3236 |
| 3237 TEST_F(DiskCacheBackendTest, TotalBuffersSize2) { |
| 3238 BackendTotalBuffersSize2(); |
| 3239 } |
| 3240 |
| 3241 TEST_F(DiskCacheBackendTest, V3TotalBuffersSize2) { |
| 3242 UseVersion3(); |
| 3243 BackendTotalBuffersSize2(); |
| 3018 } | 3244 } |
| 3019 | 3245 |
| 3020 // Tests that sharing of external files works and we are able to delete the | 3246 // Tests that sharing of external files works and we are able to delete the |
| 3021 // files when we need to. | 3247 // files when we need to. |
| 3022 TEST_F(DiskCacheBackendTest, FileSharing) { | 3248 TEST_F(DiskCacheBackendTest, FileSharing) { |
| 3023 InitCache(); | 3249 InitCache(); |
| 3024 | 3250 |
| 3025 disk_cache::Addr address(0x80000001); | 3251 disk_cache::Addr address(0x80000001); |
| 3026 ASSERT_TRUE(cache_impl_->CreateExternalFile(&address)); | 3252 ASSERT_TRUE(cache_impl_->CreateExternalFile(&address)); |
| 3027 base::FilePath name = cache_impl_->GetFileName(address); | 3253 base::FilePath name = cache_impl_->GetFileName(address); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3050 char buffer2[kSize]; | 3276 char buffer2[kSize]; |
| 3051 memset(buffer1, 't', kSize); | 3277 memset(buffer1, 't', kSize); |
| 3052 memset(buffer2, 0, kSize); | 3278 memset(buffer2, 0, kSize); |
| 3053 EXPECT_TRUE(file->Write(buffer1, kSize, 0)); | 3279 EXPECT_TRUE(file->Write(buffer1, kSize, 0)); |
| 3054 EXPECT_TRUE(file->Read(buffer2, kSize, 0)); | 3280 EXPECT_TRUE(file->Read(buffer2, kSize, 0)); |
| 3055 EXPECT_EQ(0, memcmp(buffer1, buffer2, kSize)); | 3281 EXPECT_EQ(0, memcmp(buffer1, buffer2, kSize)); |
| 3056 | 3282 |
| 3057 EXPECT_TRUE(disk_cache::DeleteCacheFile(name)); | 3283 EXPECT_TRUE(disk_cache::DeleteCacheFile(name)); |
| 3058 } | 3284 } |
| 3059 | 3285 |
| 3060 TEST_F(DiskCacheBackendTest, UpdateRankForExternalCacheHit) { | 3286 void DiskCacheBackendTest::BackendUpdateRankForExternalCacheHit() { |
| 3061 InitCache(); | 3287 InitCache(); |
| 3062 | 3288 |
| 3063 disk_cache::Entry* entry; | 3289 disk_cache::Entry* entry; |
| 3064 | 3290 |
| 3065 for (int i = 0; i < 2; ++i) { | 3291 for (int i = 0; i < 2; ++i) { |
| 3066 std::string key = base::StringPrintf("key%d", i); | 3292 std::string key = base::StringPrintf("key%d", i); |
| 3067 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 3293 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
| 3068 entry->Close(); | 3294 entry->Close(); |
| 3295 AddDelayForTest(kDelayToNextTimestamp); |
| 3069 } | 3296 } |
| 3297 FlushQueueForTest(); |
| 3070 | 3298 |
| 3071 // Ping the oldest entry. | 3299 // Ping the oldest entry. |
| 3300 SetTestMode(); |
| 3072 cache_->OnExternalCacheHit("key0"); | 3301 cache_->OnExternalCacheHit("key0"); |
| 3302 FlushQueueForTest(); |
| 3073 | 3303 |
| 3074 TrimForTest(false); | 3304 TrimForTest(false); |
| 3075 | 3305 |
| 3076 // Make sure the older key remains. | 3306 // Make sure the older key remains. |
| 3077 EXPECT_EQ(1, cache_->GetEntryCount()); | 3307 EXPECT_NE(net::OK, OpenEntry("key1", &entry)); |
| 3078 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); | 3308 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); |
| 3079 entry->Close(); | 3309 entry->Close(); |
| 3080 } | 3310 } |
| 3081 | 3311 |
| 3312 TEST_F(DiskCacheBackendTest, UpdateRankForExternalCacheHit) { |
| 3313 BackendUpdateRankForExternalCacheHit(); |
| 3314 } |
| 3315 |
| 3316 TEST_F(DiskCacheBackendTest, V3UpdateRankForExternalCacheHit) { |
| 3317 UseVersion3(); |
| 3318 BackendUpdateRankForExternalCacheHit(); |
| 3319 } |
| 3320 |
| 3082 TEST_F(DiskCacheBackendTest, ShaderCacheUpdateRankForExternalCacheHit) { | 3321 TEST_F(DiskCacheBackendTest, ShaderCacheUpdateRankForExternalCacheHit) { |
| 3083 SetCacheType(net::SHADER_CACHE); | 3322 SetCacheType(net::SHADER_CACHE); |
| 3084 InitCache(); | 3323 BackendUpdateRankForExternalCacheHit(); |
| 3324 } |
| 3085 | 3325 |
| 3086 disk_cache::Entry* entry; | 3326 TEST_F(DiskCacheBackendTest, V3ShaderCacheUpdateRankForExternalCacheHit) { |
| 3087 | 3327 UseVersion3(); |
| 3088 for (int i = 0; i < 2; ++i) { | 3328 SetCacheType(net::SHADER_CACHE); |
| 3089 std::string key = base::StringPrintf("key%d", i); | 3329 BackendUpdateRankForExternalCacheHit(); |
| 3090 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | |
| 3091 entry->Close(); | |
| 3092 } | |
| 3093 | |
| 3094 // Ping the oldest entry. | |
| 3095 cache_->OnExternalCacheHit("key0"); | |
| 3096 | |
| 3097 TrimForTest(false); | |
| 3098 | |
| 3099 // Make sure the older key remains. | |
| 3100 EXPECT_EQ(1, cache_->GetEntryCount()); | |
| 3101 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); | |
| 3102 entry->Close(); | |
| 3103 } | 3330 } |
| 3104 | 3331 |
| 3105 void DiskCacheBackendTest::TracingBackendBasics() { | 3332 void DiskCacheBackendTest::TracingBackendBasics() { |
| 3106 InitCache(); | 3333 InitCache(); |
| 3107 cache_.reset(new disk_cache::TracingCacheBackend(cache_.Pass())); | 3334 cache_.reset(new disk_cache::TracingCacheBackend(cache_.Pass())); |
| 3108 cache_impl_ = NULL; | 3335 cache_impl_ = NULL; |
| 3109 EXPECT_EQ(net::DISK_CACHE, cache_->GetCacheType()); | 3336 EXPECT_EQ(net::DISK_CACHE, cache_->GetCacheType()); |
| 3110 if (!simple_cache_mode_) { | 3337 if (!simple_cache_mode_) { |
| 3111 EXPECT_EQ(0, cache_->GetEntryCount()); | 3338 EXPECT_EQ(0, cache_->GetEntryCount()); |
| 3112 } | 3339 } |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3464 void* iter = NULL; | 3691 void* iter = NULL; |
| 3465 size_t count = 0; | 3692 size_t count = 0; |
| 3466 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count)); | 3693 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count)); |
| 3467 cache_->EndEnumeration(&iter); | 3694 cache_->EndEnumeration(&iter); |
| 3468 | 3695 |
| 3469 EXPECT_EQ(key_pool.size(), count); | 3696 EXPECT_EQ(key_pool.size(), count); |
| 3470 EXPECT_TRUE(keys_to_match.empty()); | 3697 EXPECT_TRUE(keys_to_match.empty()); |
| 3471 } | 3698 } |
| 3472 | 3699 |
| 3473 #endif // defined(OS_POSIX) | 3700 #endif // defined(OS_POSIX) |
| OLD | NEW |