| 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 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 TEST_F(CacheStorageManagerTest, BadOriginName) { | 555 TEST_F(CacheStorageManagerTest, BadOriginName) { |
| 556 // Since the implementation writes origin names to disk, ensure that we don't | 556 // Since the implementation writes origin names to disk, ensure that we don't |
| 557 // escape the directory. | 557 // escape the directory. |
| 558 GURL bad_origin("http://../../../../../../../../../../../../../../foo"); | 558 GURL bad_origin("http://../../../../../../../../../../../../../../foo"); |
| 559 EXPECT_TRUE(Open(bad_origin, "foo")); | 559 EXPECT_TRUE(Open(bad_origin, "foo")); |
| 560 EXPECT_TRUE(Keys(bad_origin)); | 560 EXPECT_TRUE(Keys(bad_origin)); |
| 561 EXPECT_EQ(1u, callback_strings_.size()); | 561 EXPECT_EQ(1u, callback_strings_.size()); |
| 562 EXPECT_STREQ("foo", callback_strings_[0].c_str()); | 562 EXPECT_STREQ("foo", callback_strings_[0].c_str()); |
| 563 } | 563 } |
| 564 | 564 |
| 565 // With a persistent cache if the client drops its reference to a | |
| 566 // CacheStorageCache | |
| 567 // it should be deleted. | |
| 568 TEST_F(CacheStorageManagerTest, DropReference) { | |
| 569 EXPECT_TRUE(Open(origin1_, "foo")); | |
| 570 base::WeakPtr<CacheStorageCache> cache = callback_cache_->AsWeakPtr(); | |
| 571 callback_cache_ = NULL; | |
| 572 EXPECT_TRUE(!cache); | |
| 573 } | |
| 574 | |
| 575 // With a memory cache the cache can't be freed from memory until the client | |
| 576 // calls delete. | |
| 577 TEST_F(CacheStorageManagerMemoryOnlyTest, MemoryLosesReferenceOnlyAfterDelete) { | |
| 578 EXPECT_TRUE(Open(origin1_, "foo")); | |
| 579 base::WeakPtr<CacheStorageCache> cache = callback_cache_->AsWeakPtr(); | |
| 580 callback_cache_ = NULL; | |
| 581 EXPECT_TRUE(cache); | |
| 582 EXPECT_TRUE(Delete(origin1_, "foo")); | |
| 583 EXPECT_FALSE(cache); | |
| 584 } | |
| 585 | |
| 586 TEST_P(CacheStorageManagerTestP, DeleteBeforeRelease) { | 565 TEST_P(CacheStorageManagerTestP, DeleteBeforeRelease) { |
| 587 EXPECT_TRUE(Open(origin1_, "foo")); | 566 EXPECT_TRUE(Open(origin1_, "foo")); |
| 588 EXPECT_TRUE(Delete(origin1_, "foo")); | 567 EXPECT_TRUE(Delete(origin1_, "foo")); |
| 589 EXPECT_TRUE(callback_cache_->AsWeakPtr()); | 568 EXPECT_TRUE(callback_cache_->AsWeakPtr()); |
| 590 } | 569 } |
| 591 | 570 |
| 592 TEST_P(CacheStorageManagerTestP, OpenRunsSerially) { | 571 TEST_P(CacheStorageManagerTestP, OpenRunsSerially) { |
| 593 EXPECT_FALSE(Delete(origin1_, "tmp")); // Init storage. | 572 EXPECT_FALSE(Delete(origin1_, "tmp")); // Init storage. |
| 594 CacheStorage* cache_storage = CacheStorageForOrigin(origin1_); | 573 CacheStorage* cache_storage = CacheStorageForOrigin(origin1_); |
| 595 cache_storage->StartAsyncOperationForTesting(); | 574 cache_storage->StartAsyncOperationForTesting(); |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 | 990 |
| 1012 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, | 991 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, |
| 1013 CacheStorageManagerTestP, | 992 CacheStorageManagerTestP, |
| 1014 ::testing::Values(false, true)); | 993 ::testing::Values(false, true)); |
| 1015 | 994 |
| 1016 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, | 995 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, |
| 1017 CacheStorageQuotaClientTestP, | 996 CacheStorageQuotaClientTestP, |
| 1018 ::testing::Values(false, true)); | 997 ::testing::Values(false, true)); |
| 1019 | 998 |
| 1020 } // namespace content | 999 } // namespace content |
| OLD | NEW |