| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 3868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3879 OpenEntry(*(keys_to_match.begin()), &entry_opened_middle)); | 3879 OpenEntry(*(keys_to_match.begin()), &entry_opened_middle)); |
| 3880 ASSERT_TRUE(EnumerateAndMatchKeys(-1, iter.get(), &keys_to_match, &count)); | 3880 ASSERT_TRUE(EnumerateAndMatchKeys(-1, iter.get(), &keys_to_match, &count)); |
| 3881 iter.reset(); | 3881 iter.reset(); |
| 3882 entry_opened_before->Close(); | 3882 entry_opened_before->Close(); |
| 3883 entry_opened_middle->Close(); | 3883 entry_opened_middle->Close(); |
| 3884 | 3884 |
| 3885 EXPECT_EQ(key_pool.size(), count); | 3885 EXPECT_EQ(key_pool.size(), count); |
| 3886 EXPECT_TRUE(keys_to_match.empty()); | 3886 EXPECT_TRUE(keys_to_match.empty()); |
| 3887 } | 3887 } |
| 3888 | 3888 |
| 3889 TEST_F(DiskCacheBackendTest, SimpleCacheIndexRecovery) { | |
| 3890 // Make sure we can recover set of entries when the index was removed. | |
| 3891 SetSimpleCacheMode(); | |
| 3892 InitCache(); | |
| 3893 std::set<std::string> key_pool; | |
| 3894 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool)); | |
| 3895 | |
| 3896 cache_.reset(); | |
| 3897 | |
| 3898 // Give it a chance to write out the index, so we can delete it (rather | |
| 3899 // than have it write it after we delete it). | |
| 3900 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); | |
| 3901 base::RunLoop().RunUntilIdle(); | |
| 3902 | |
| 3903 base::FilePath index_path = | |
| 3904 cache_path_.AppendASCII("index-dir").AppendASCII("the-real-index"); | |
| 3905 ASSERT_TRUE(base::DeleteFile(index_path, false)); | |
| 3906 | |
| 3907 DisableFirstCleanup(); | |
| 3908 InitCache(); | |
| 3909 // A bit surprising, but it calls it "NEWCACHE" if there was no index, | |
| 3910 // even if it reconstructed non-zero things. | |
| 3911 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_NEWCACHE, | |
| 3912 simple_cache_impl_->index()->init_method()); | |
| 3913 | |
| 3914 // Check that enumeration returns all entries. | |
| 3915 std::set<std::string> keys_to_match(key_pool); | |
| 3916 std::unique_ptr<TestIterator> iter = CreateIterator(); | |
| 3917 size_t count = 0; | |
| 3918 ASSERT_TRUE(EnumerateAndMatchKeys(-1, iter.get(), &keys_to_match, &count)); | |
| 3919 iter.reset(); | |
| 3920 EXPECT_EQ(key_pool.size(), count); | |
| 3921 EXPECT_TRUE(keys_to_match.empty()); | |
| 3922 } | |
| 3923 | |
| 3924 // Tests that the enumerations are not affected by dooming an entry in the | 3889 // Tests that the enumerations are not affected by dooming an entry in the |
| 3925 // middle. | 3890 // middle. |
| 3926 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationWhileDoomed) { | 3891 TEST_F(DiskCacheBackendTest, SimpleCacheEnumerationWhileDoomed) { |
| 3927 SetSimpleCacheMode(); | 3892 SetSimpleCacheMode(); |
| 3928 InitCache(); | 3893 InitCache(); |
| 3929 std::set<std::string> key_pool; | 3894 std::set<std::string> key_pool; |
| 3930 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool)); | 3895 ASSERT_TRUE(CreateSetOfRandomEntries(&key_pool)); |
| 3931 | 3896 |
| 3932 // Check that enumeration returns all entries but the doomed one. | 3897 // Check that enumeration returns all entries but the doomed one. |
| 3933 std::set<std::string> keys_to_match(key_pool); | 3898 std::set<std::string> keys_to_match(key_pool); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4119 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); | 4084 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); |
| 4120 base::RunLoop().RunUntilIdle(); | 4085 base::RunLoop().RunUntilIdle(); |
| 4121 | 4086 |
| 4122 disk_cache::Entry* reopen_entry1; | 4087 disk_cache::Entry* reopen_entry1; |
| 4123 ASSERT_THAT(OpenEntry(key1, &reopen_entry1), IsOk()); | 4088 ASSERT_THAT(OpenEntry(key1, &reopen_entry1), IsOk()); |
| 4124 | 4089 |
| 4125 // This shouldn't pick up entry2's write time incorrectly. | 4090 // This shouldn't pick up entry2's write time incorrectly. |
| 4126 EXPECT_LE(reopen_entry1->GetLastModified(), entry1_timestamp); | 4091 EXPECT_LE(reopen_entry1->GetLastModified(), entry1_timestamp); |
| 4127 reopen_entry1->Close(); | 4092 reopen_entry1->Close(); |
| 4128 } | 4093 } |
| OLD | NEW |