Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: content/browser/cache_storage/cache_storage_manager_unittest.cc

Issue 1421863002: [CacheStorage] Garbage collect unreferenced caches (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@random_cache_name
Patch Set: Nits Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 } 646 }
647 647
648 TEST_F(CacheStorageManagerTest, MemoryBackedSizePersistent) { 648 TEST_F(CacheStorageManagerTest, MemoryBackedSizePersistent) {
649 CacheStorage* cache_storage = CacheStorageForOrigin(origin1_); 649 CacheStorage* cache_storage = CacheStorageForOrigin(origin1_);
650 EXPECT_EQ(0, cache_storage->MemoryBackedSize()); 650 EXPECT_EQ(0, cache_storage->MemoryBackedSize());
651 EXPECT_TRUE(Open(origin1_, "foo")); 651 EXPECT_TRUE(Open(origin1_, "foo"));
652 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo"))); 652 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo")));
653 EXPECT_EQ(0, cache_storage->MemoryBackedSize()); 653 EXPECT_EQ(0, cache_storage->MemoryBackedSize());
654 } 654 }
655 655
656 TEST_F(CacheStorageManagerTest, DeleteUnreferencedCacheDirectories) {
657 // Create a referenced cache.
658 EXPECT_TRUE(Open(origin1_, "foo"));
659 EXPECT_TRUE(CachePut(callback_cache_, GURL("http://example.com/foo")));
660
661 // Create an unreferenced directory next to the referenced one.
662 base::FilePath origin_path = CacheStorageManager::ConstructOriginPath(
663 cache_manager_->root_path(), origin1_);
664 base::FilePath unreferenced_path = origin_path.AppendASCII("bar");
665 EXPECT_TRUE(CreateDirectory(unreferenced_path));
666 EXPECT_TRUE(base::DirectoryExists(unreferenced_path));
667
668 // Create a new StorageManager so that the next time the cache is opened
669 // the unreferenced directory can be deleted.
670 quota_manager_proxy_->SimulateQuotaManagerDestroyed();
671 cache_manager_ = CacheStorageManager::Create(cache_manager_.get());
672
673 // Verify that the referenced cache still works.
674 EXPECT_TRUE(Open(origin1_, "foo"));
675 EXPECT_TRUE(CacheMatch(callback_cache_, GURL("http://example.com/foo")));
676
677 // Verify that the unreferenced cache is gone.
678 EXPECT_FALSE(base::DirectoryExists(unreferenced_path));
679 }
680
656 class CacheStorageMigrationTest : public CacheStorageManagerTest { 681 class CacheStorageMigrationTest : public CacheStorageManagerTest {
657 protected: 682 protected:
658 CacheStorageMigrationTest() : cache1_("foo"), cache2_("bar") {} 683 CacheStorageMigrationTest() : cache1_("foo"), cache2_("bar") {}
659 684
660 void SetUp() override { 685 void SetUp() override {
661 CacheStorageManagerTest::SetUp(); 686 CacheStorageManagerTest::SetUp();
662 687
663 // Populate a cache, then move it to the "legacy" location 688 // Populate a cache, then move it to the "legacy" location
664 // so that tests can verify the results of migration. 689 // so that tests can verify the results of migration.
665 legacy_path_ = CacheStorageManager::ConstructLegacyOriginPath( 690 legacy_path_ = CacheStorageManager::ConstructLegacyOriginPath(
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 1007
983 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, 1008 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests,
984 CacheStorageManagerTestP, 1009 CacheStorageManagerTestP,
985 ::testing::Values(false, true)); 1010 ::testing::Values(false, true));
986 1011
987 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, 1012 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests,
988 CacheStorageQuotaClientTestP, 1013 CacheStorageQuotaClientTestP,
989 ::testing::Values(false, true)); 1014 ::testing::Values(false, true));
990 1015
991 } // namespace content 1016 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698