| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 EXPECT_EQ(1u, callback_strings_.size()); | 643 EXPECT_EQ(1u, callback_strings_.size()); |
| 644 EXPECT_STREQ("foo", callback_strings_[0].c_str()); | 644 EXPECT_STREQ("foo", callback_strings_[0].c_str()); |
| 645 } | 645 } |
| 646 | 646 |
| 647 // With a persistent cache if the client drops its reference to a | 647 // With a persistent cache if the client drops its reference to a |
| 648 // CacheStorageCache it should be deleted. | 648 // CacheStorageCache it should be deleted. |
| 649 TEST_F(CacheStorageManagerTest, DropReference) { | 649 TEST_F(CacheStorageManagerTest, DropReference) { |
| 650 EXPECT_TRUE(Open(origin1_, "foo")); | 650 EXPECT_TRUE(Open(origin1_, "foo")); |
| 651 base::WeakPtr<CacheStorageCache> cache = | 651 base::WeakPtr<CacheStorageCache> cache = |
| 652 callback_cache_handle_->value()->AsWeakPtr(); | 652 callback_cache_handle_->value()->AsWeakPtr(); |
| 653 // Run a cache operation to ensure that the cache has finished initializing so |
| 654 // that when the handle is dropped it can close immediately. |
| 655 EXPECT_FALSE(CacheMatch(callback_cache_handle_->value(), |
| 656 GURL("http://example.com/foo"))); |
| 657 |
| 653 callback_cache_handle_ = nullptr; | 658 callback_cache_handle_ = nullptr; |
| 654 EXPECT_FALSE(cache); | 659 EXPECT_FALSE(cache); |
| 655 } | 660 } |
| 656 | 661 |
| 657 // A cache continues to work so long as there is a handle to it. Only after the | 662 // A cache continues to work so long as there is a handle to it. Only after the |
| 658 // last cache handle is deleted can the cache be freed. | 663 // last cache handle is deleted can the cache be freed. |
| 659 TEST_P(CacheStorageManagerTestP, CacheWorksAfterDelete) { | 664 TEST_P(CacheStorageManagerTestP, CacheWorksAfterDelete) { |
| 660 const GURL kFooURL("http://example.com/foo"); | 665 const GURL kFooURL("http://example.com/foo"); |
| 661 const GURL kBarURL("http://example.com/bar"); | 666 const GURL kBarURL("http://example.com/bar"); |
| 662 const GURL kBazURL("http://example.com/baz"); | 667 const GURL kBazURL("http://example.com/baz"); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 legacy_path_ = CacheStorageManager::ConstructLegacyOriginPath( | 892 legacy_path_ = CacheStorageManager::ConstructLegacyOriginPath( |
| 888 cache_manager_->root_path(), origin1_); | 893 cache_manager_->root_path(), origin1_); |
| 889 new_path_ = CacheStorageManager::ConstructOriginPath( | 894 new_path_ = CacheStorageManager::ConstructOriginPath( |
| 890 cache_manager_->root_path(), origin1_); | 895 cache_manager_->root_path(), origin1_); |
| 891 | 896 |
| 892 ASSERT_FALSE(base::DirectoryExists(legacy_path_)); | 897 ASSERT_FALSE(base::DirectoryExists(legacy_path_)); |
| 893 ASSERT_FALSE(base::DirectoryExists(new_path_)); | 898 ASSERT_FALSE(base::DirectoryExists(new_path_)); |
| 894 ASSERT_TRUE(Open(origin1_, cache1_)); | 899 ASSERT_TRUE(Open(origin1_, cache1_)); |
| 895 ASSERT_TRUE(Open(origin1_, cache2_)); | 900 ASSERT_TRUE(Open(origin1_, cache2_)); |
| 896 callback_cache_handle_.reset(); | 901 callback_cache_handle_.reset(); |
| 902 |
| 903 // Let the caches shut down. |
| 904 base::RunLoop().RunUntilIdle(); |
| 905 |
| 897 ASSERT_FALSE(base::DirectoryExists(legacy_path_)); | 906 ASSERT_FALSE(base::DirectoryExists(legacy_path_)); |
| 898 ASSERT_TRUE(base::DirectoryExists(new_path_)); | 907 ASSERT_TRUE(base::DirectoryExists(new_path_)); |
| 899 | 908 |
| 900 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); | 909 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); |
| 901 cache_manager_ = CacheStorageManager::Create(cache_manager_.get()); | 910 cache_manager_ = CacheStorageManager::Create(cache_manager_.get()); |
| 902 | 911 |
| 903 ASSERT_TRUE(base::Move(new_path_, legacy_path_)); | 912 ASSERT_TRUE(base::Move(new_path_, legacy_path_)); |
| 904 ASSERT_TRUE(base::DirectoryExists(legacy_path_)); | 913 ASSERT_TRUE(base::DirectoryExists(legacy_path_)); |
| 905 ASSERT_FALSE(base::DirectoryExists(new_path_)); | 914 ASSERT_FALSE(base::DirectoryExists(new_path_)); |
| 906 } | 915 } |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1241 | 1250 |
| 1242 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, | 1251 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, |
| 1243 CacheStorageManagerTestP, | 1252 CacheStorageManagerTestP, |
| 1244 ::testing::Values(false, true)); | 1253 ::testing::Values(false, true)); |
| 1245 | 1254 |
| 1246 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, | 1255 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, |
| 1247 CacheStorageQuotaClientTestP, | 1256 CacheStorageQuotaClientTestP, |
| 1248 ::testing::Values(false, true)); | 1257 ::testing::Values(false, true)); |
| 1249 | 1258 |
| 1250 } // namespace content | 1259 } // namespace content |
| OLD | NEW |