| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/cache_storage/cache_storage_manager.h" | 5 #include "content/browser/cache_storage/cache_storage_manager.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/guid.h" | 10 #include "base/guid.h" |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 } | 648 } |
| 649 | 649 |
| 650 TEST_F(CacheStorageManagerTest, MemoryBackedSizePersistent) { | 650 TEST_F(CacheStorageManagerTest, MemoryBackedSizePersistent) { |
| 651 CacheStorage* cache_storage = CacheStorageForOrigin(origin1_); | 651 CacheStorage* cache_storage = CacheStorageForOrigin(origin1_); |
| 652 EXPECT_EQ(0, cache_storage->MemoryBackedSize()); | 652 EXPECT_EQ(0, cache_storage->MemoryBackedSize()); |
| 653 EXPECT_TRUE(Open(origin1_, "foo")); | 653 EXPECT_TRUE(Open(origin1_, "foo")); |
| 654 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo"))); | 654 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo"))); |
| 655 EXPECT_EQ(0, cache_storage->MemoryBackedSize()); | 655 EXPECT_EQ(0, cache_storage->MemoryBackedSize()); |
| 656 } | 656 } |
| 657 | 657 |
| 658 TEST_F(CacheStorageManagerTest, DeleteUnreferencedCacheDirectories) { |
| 659 // Create a referenced cache. |
| 660 EXPECT_TRUE(Open(origin1_, "foo")); |
| 661 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo"))); |
| 662 |
| 663 // Create an unreferenced directory next to the referenced one. |
| 664 base::FilePath origin_path = CacheStorageManager::ConstructOriginPath( |
| 665 cache_manager_->root_path(), origin1_); |
| 666 base::FilePath unreferenced_path = origin_path.AppendASCII("bar"); |
| 667 EXPECT_TRUE(CreateDirectory(unreferenced_path)); |
| 668 EXPECT_TRUE(base::DirectoryExists(unreferenced_path)); |
| 669 |
| 670 // Create a new StorageManager so that the next time the cache is opened |
| 671 // the unreferenced directory can be deleted. |
| 672 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); |
| 673 cache_manager_ = CacheStorageManager::Create(cache_manager_.get()); |
| 674 |
| 675 // Verify that the referenced cache still works. |
| 676 EXPECT_TRUE(Open(origin1_, "foo")); |
| 677 EXPECT_TRUE(CacheMatch(callback_cache_, GURL("http://example.com/foo"))); |
| 678 |
| 679 // Verify that the unreferenced cache is gone. |
| 680 EXPECT_FALSE(base::DirectoryExists(unreferenced_path)); |
| 681 } |
| 682 |
| 658 class CacheStorageMigrationTest : public CacheStorageManagerTest { | 683 class CacheStorageMigrationTest : public CacheStorageManagerTest { |
| 659 protected: | 684 protected: |
| 660 CacheStorageMigrationTest() : cache1_("foo"), cache2_("bar") {} | 685 CacheStorageMigrationTest() : cache1_("foo"), cache2_("bar") {} |
| 661 | 686 |
| 662 void SetUp() override { | 687 void SetUp() override { |
| 663 CacheStorageManagerTest::SetUp(); | 688 CacheStorageManagerTest::SetUp(); |
| 664 | 689 |
| 665 // Populate a cache, then move it to the "legacy" location | 690 // Populate a cache, then move it to the "legacy" location |
| 666 // so that tests can verify the results of migration. | 691 // so that tests can verify the results of migration. |
| 667 legacy_path_ = CacheStorageManager::ConstructLegacyOriginPath( | 692 legacy_path_ = CacheStorageManager::ConstructLegacyOriginPath( |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 | 1009 |
| 985 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, | 1010 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, |
| 986 CacheStorageManagerTestP, | 1011 CacheStorageManagerTestP, |
| 987 ::testing::Values(false, true)); | 1012 ::testing::Values(false, true)); |
| 988 | 1013 |
| 989 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, | 1014 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, |
| 990 CacheStorageQuotaClientTestP, | 1015 CacheStorageQuotaClientTestP, |
| 991 ::testing::Values(false, true)); | 1016 ::testing::Values(false, true)); |
| 992 | 1017 |
| 993 } // namespace content | 1018 } // namespace content |
| OLD | NEW |