| 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 bool Open(const GURL& origin, const std::string& cache_name) { | 158 bool Open(const GURL& origin, const std::string& cache_name) { |
| 159 base::RunLoop loop; | 159 base::RunLoop loop; |
| 160 cache_manager_->OpenCache( | 160 cache_manager_->OpenCache( |
| 161 origin, cache_name, | 161 origin, cache_name, |
| 162 base::Bind(&CacheStorageManagerTest::CacheAndErrorCallback, | 162 base::Bind(&CacheStorageManagerTest::CacheAndErrorCallback, |
| 163 base::Unretained(this), base::Unretained(&loop))); | 163 base::Unretained(this), base::Unretained(&loop))); |
| 164 loop.Run(); | 164 loop.Run(); |
| 165 | 165 |
| 166 bool error = callback_error_ != CACHE_STORAGE_OK; | 166 bool error = callback_error_ != CACHE_STORAGE_OK; |
| 167 if (error) | 167 if (error) |
| 168 EXPECT_TRUE(!callback_cache_handle_); | 168 EXPECT_FALSE(callback_cache_handle_); |
| 169 else | 169 else |
| 170 EXPECT_TRUE(callback_cache_handle_); | 170 EXPECT_TRUE(callback_cache_handle_); |
| 171 return !error; | 171 return !error; |
| 172 } | 172 } |
| 173 | 173 |
| 174 bool Has(const GURL& origin, const std::string& cache_name) { | 174 bool Has(const GURL& origin, const std::string& cache_name) { |
| 175 base::RunLoop loop; | 175 base::RunLoop loop; |
| 176 cache_manager_->HasCache( | 176 cache_manager_->HasCache( |
| 177 origin, cache_name, | 177 origin, cache_name, |
| 178 base::Bind(&CacheStorageManagerTest::BoolAndErrorCallback, | 178 base::Bind(&CacheStorageManagerTest::BoolAndErrorCallback, |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 TEST_F(CacheStorageManagerTest, BadOriginName) { | 632 TEST_F(CacheStorageManagerTest, BadOriginName) { |
| 633 // Since the implementation writes origin names to disk, ensure that we don't | 633 // Since the implementation writes origin names to disk, ensure that we don't |
| 634 // escape the directory. | 634 // escape the directory. |
| 635 GURL bad_origin("http://../../../../../../../../../../../../../../foo"); | 635 GURL bad_origin("http://../../../../../../../../../../../../../../foo"); |
| 636 EXPECT_TRUE(Open(bad_origin, "foo")); | 636 EXPECT_TRUE(Open(bad_origin, "foo")); |
| 637 EXPECT_TRUE(Keys(bad_origin)); | 637 EXPECT_TRUE(Keys(bad_origin)); |
| 638 EXPECT_EQ(1u, callback_strings_.size()); | 638 EXPECT_EQ(1u, callback_strings_.size()); |
| 639 EXPECT_STREQ("foo", callback_strings_[0].c_str()); | 639 EXPECT_STREQ("foo", callback_strings_[0].c_str()); |
| 640 } | 640 } |
| 641 | 641 |
| 642 // With a persistent cache if the client drops its reference to a |
| 643 // CacheStorageCache it should be deleted. |
| 644 TEST_F(CacheStorageManagerTest, DropReference) { |
| 645 EXPECT_TRUE(Open(origin1_, "foo")); |
| 646 base::WeakPtr<CacheStorageCache> cache = |
| 647 callback_cache_handle_->value()->AsWeakPtr(); |
| 648 callback_cache_handle_ = nullptr; |
| 649 EXPECT_FALSE(cache); |
| 650 } |
| 651 |
| 652 // With a memory cache the cache can't be freed from memory until the client |
| 653 // calls delete. |
| 654 TEST_F(CacheStorageManagerMemoryOnlyTest, MemoryLosesReferenceOnlyAfterDelete) { |
| 655 EXPECT_TRUE(Open(origin1_, "foo")); |
| 656 base::WeakPtr<CacheStorageCache> cache = |
| 657 callback_cache_handle_->value()->AsWeakPtr(); |
| 658 callback_cache_handle_ = nullptr; |
| 659 EXPECT_TRUE(cache); |
| 660 EXPECT_TRUE(Delete(origin1_, "foo")); |
| 661 EXPECT_FALSE(cache); |
| 662 } |
| 663 |
| 642 TEST_P(CacheStorageManagerTestP, DeleteBeforeRelease) { | 664 TEST_P(CacheStorageManagerTestP, DeleteBeforeRelease) { |
| 643 EXPECT_TRUE(Open(origin1_, "foo")); | 665 EXPECT_TRUE(Open(origin1_, "foo")); |
| 644 EXPECT_TRUE(Delete(origin1_, "foo")); | 666 EXPECT_TRUE(Delete(origin1_, "foo")); |
| 645 EXPECT_TRUE(callback_cache_handle_->value()); | 667 EXPECT_TRUE(callback_cache_handle_->value()); |
| 646 } | 668 } |
| 647 | 669 |
| 648 TEST_P(CacheStorageManagerTestP, OpenRunsSerially) { | 670 TEST_P(CacheStorageManagerTestP, OpenRunsSerially) { |
| 649 EXPECT_FALSE(Delete(origin1_, "tmp")); // Init storage. | 671 EXPECT_FALSE(Delete(origin1_, "tmp")); // Init storage. |
| 650 CacheStorage* cache_storage = CacheStorageForOrigin(origin1_); | 672 CacheStorage* cache_storage = CacheStorageForOrigin(origin1_); |
| 651 cache_storage->StartAsyncOperationForTesting(); | 673 cache_storage->StartAsyncOperationForTesting(); |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 | 1198 |
| 1177 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, | 1199 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, |
| 1178 CacheStorageManagerTestP, | 1200 CacheStorageManagerTestP, |
| 1179 ::testing::Values(false, true)); | 1201 ::testing::Values(false, true)); |
| 1180 | 1202 |
| 1181 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, | 1203 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, |
| 1182 CacheStorageQuotaClientTestP, | 1204 CacheStorageQuotaClientTestP, |
| 1183 ::testing::Values(false, true)); | 1205 ::testing::Values(false, true)); |
| 1184 | 1206 |
| 1185 } // namespace content | 1207 } // namespace content |
| OLD | NEW |