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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 2135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2146 entry1->Doom(); | 2146 entry1->Doom(); |
2147 entry1->Close(); | 2147 entry1->Close(); |
2148 entry2->Close(); | 2148 entry2->Close(); |
2149 | 2149 |
2150 // Doom the second entry after it's fully saved. | 2150 // Doom the second entry after it's fully saved. |
2151 EXPECT_EQ(net::OK, DoomEntry(key2)); | 2151 EXPECT_EQ(net::OK, DoomEntry(key2)); |
2152 | 2152 |
2153 // Make sure we do all needed work. This may fail for entry2 if between Close | 2153 // Make sure we do all needed work. This may fail for entry2 if between Close |
2154 // and DoomEntry the system decides to remove all traces of the file from the | 2154 // and DoomEntry the system decides to remove all traces of the file from the |
2155 // system cache so we don't see that there is pending IO. | 2155 // system cache so we don't see that there is pending IO. |
2156 base::MessageLoop::current()->RunUntilIdle(); | 2156 base::RunLoop().RunUntilIdle(); |
2157 | 2157 |
2158 if (memory_only_) { | 2158 if (memory_only_) { |
2159 EXPECT_EQ(0, cache_->GetEntryCount()); | 2159 EXPECT_EQ(0, cache_->GetEntryCount()); |
2160 } else { | 2160 } else { |
2161 if (5 == cache_->GetEntryCount()) { | 2161 if (5 == cache_->GetEntryCount()) { |
2162 // Most likely we are waiting for the result of reading the sparse info | 2162 // Most likely we are waiting for the result of reading the sparse info |
2163 // (it's always async on Posix so it is easy to miss). Unfortunately we | 2163 // (it's always async on Posix so it is easy to miss). Unfortunately we |
2164 // don't have any signal to watch for so we can only wait. | 2164 // don't have any signal to watch for so we can only wait. |
2165 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(500)); | 2165 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(500)); |
2166 base::MessageLoop::current()->RunUntilIdle(); | 2166 base::RunLoop().RunUntilIdle(); |
2167 } | 2167 } |
2168 EXPECT_EQ(0, cache_->GetEntryCount()); | 2168 EXPECT_EQ(0, cache_->GetEntryCount()); |
2169 } | 2169 } |
2170 } | 2170 } |
2171 | 2171 |
2172 TEST_F(DiskCacheEntryTest, DoomSparseEntry) { | 2172 TEST_F(DiskCacheEntryTest, DoomSparseEntry) { |
2173 UseCurrentThread(); | 2173 UseCurrentThread(); |
2174 InitCache(); | 2174 InitCache(); |
2175 DoomSparseEntry(); | 2175 DoomSparseEntry(); |
2176 } | 2176 } |
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3027 | 3027 |
3028 // Lets do a Write so we block until both the Close and the Write | 3028 // Lets do a Write so we block until both the Close and the Write |
3029 // operation finishes. Write must fail since we are writing in a closed entry. | 3029 // operation finishes. Write must fail since we are writing in a closed entry. |
3030 EXPECT_EQ( | 3030 EXPECT_EQ( |
3031 net::ERR_IO_PENDING, | 3031 net::ERR_IO_PENDING, |
3032 entry->WriteData(1, 0, buffer1.get(), kSize1, cb.callback(), false)); | 3032 entry->WriteData(1, 0, buffer1.get(), kSize1, cb.callback(), false)); |
3033 EXPECT_EQ(net::ERR_FAILED, cb.GetResult(net::ERR_IO_PENDING)); | 3033 EXPECT_EQ(net::ERR_FAILED, cb.GetResult(net::ERR_IO_PENDING)); |
3034 | 3034 |
3035 // Finish running the pending tasks so that we fully complete the close | 3035 // Finish running the pending tasks so that we fully complete the close |
3036 // operation and destroy the entry object. | 3036 // operation and destroy the entry object. |
3037 base::MessageLoop::current()->RunUntilIdle(); | 3037 base::RunLoop().RunUntilIdle(); |
3038 | 3038 |
3039 // At this point the |entry| must have been destroyed, and called | 3039 // At this point the |entry| must have been destroyed, and called |
3040 // RemoveSelfFromBackend(). | 3040 // RemoveSelfFromBackend(). |
3041 disk_cache::Entry* entry2 = NULL; | 3041 disk_cache::Entry* entry2 = NULL; |
3042 ASSERT_EQ(net::ERR_IO_PENDING, | 3042 ASSERT_EQ(net::ERR_IO_PENDING, |
3043 cache_->OpenEntry(key, &entry2, cb.callback())); | 3043 cache_->OpenEntry(key, &entry2, cb.callback())); |
3044 ASSERT_EQ(net::OK, cb.GetResult(net::ERR_IO_PENDING)); | 3044 ASSERT_EQ(net::OK, cb.GetResult(net::ERR_IO_PENDING)); |
3045 EXPECT_NE(null, entry2); | 3045 EXPECT_NE(null, entry2); |
3046 | 3046 |
3047 disk_cache::Entry* entry3 = NULL; | 3047 disk_cache::Entry* entry3 = NULL; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3201 EXPECT_EQ(net::OK, cb.GetResult(net::ERR_IO_PENDING)); | 3201 EXPECT_EQ(net::OK, cb.GetResult(net::ERR_IO_PENDING)); |
3202 | 3202 |
3203 EXPECT_EQ( | 3203 EXPECT_EQ( |
3204 kSize1, | 3204 kSize1, |
3205 entry->WriteData(0, 0, buffer1.get(), kSize1, cb.callback(), false)); | 3205 entry->WriteData(0, 0, buffer1.get(), kSize1, cb.callback(), false)); |
3206 | 3206 |
3207 entry->Close(); | 3207 entry->Close(); |
3208 | 3208 |
3209 // Finish running the pending tasks so that we fully complete the close | 3209 // Finish running the pending tasks so that we fully complete the close |
3210 // operation and destroy the entry object. | 3210 // operation and destroy the entry object. |
3211 base::MessageLoop::current()->RunUntilIdle(); | 3211 base::RunLoop().RunUntilIdle(); |
3212 | 3212 |
3213 for (int i = 0; i < disk_cache::kSimpleEntryFileCount; ++i) { | 3213 for (int i = 0; i < disk_cache::kSimpleEntryFileCount; ++i) { |
3214 base::FilePath entry_file_path = cache_path_.AppendASCII( | 3214 base::FilePath entry_file_path = cache_path_.AppendASCII( |
3215 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, i)); | 3215 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, i)); |
3216 base::File::Info info; | 3216 base::File::Info info; |
3217 EXPECT_FALSE(base::GetFileInfo(entry_file_path, &info)); | 3217 EXPECT_FALSE(base::GetFileInfo(entry_file_path, &info)); |
3218 } | 3218 } |
3219 } | 3219 } |
3220 | 3220 |
3221 TEST_F(DiskCacheEntryTest, SimpleCacheDoomCreateRace) { | 3221 TEST_F(DiskCacheEntryTest, SimpleCacheDoomCreateRace) { |
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4049 // Close does not have a callback. However, we need to be sure the close is | 4049 // Close does not have a callback. However, we need to be sure the close is |
4050 // finished before we continue the test. We can take advantage of how the ref | 4050 // finished before we continue the test. We can take advantage of how the ref |
4051 // counting of a SimpleEntryImpl works to fake out a callback: When the | 4051 // counting of a SimpleEntryImpl works to fake out a callback: When the |
4052 // last Close() call is made to an entry, an IO operation is sent to the | 4052 // last Close() call is made to an entry, an IO operation is sent to the |
4053 // synchronous entry to close the platform files. This IO operation holds a | 4053 // synchronous entry to close the platform files. This IO operation holds a |
4054 // ref pointer to the entry, which expires when the operation is done. So, | 4054 // ref pointer to the entry, which expires when the operation is done. So, |
4055 // we take a refpointer, and watch the SimpleEntry object until it has only | 4055 // we take a refpointer, and watch the SimpleEntry object until it has only |
4056 // one ref; this indicates the IO operation is complete. | 4056 // one ref; this indicates the IO operation is complete. |
4057 while (!entry1_refptr->HasOneRef()) { | 4057 while (!entry1_refptr->HasOneRef()) { |
4058 base::PlatformThread::YieldCurrentThread(); | 4058 base::PlatformThread::YieldCurrentThread(); |
4059 base::MessageLoop::current()->RunUntilIdle(); | 4059 base::RunLoop().RunUntilIdle(); |
4060 } | 4060 } |
4061 entry1_refptr = NULL; | 4061 entry1_refptr = NULL; |
4062 | 4062 |
4063 // In the bug case, this new entry ends up being a duplicate object pointing | 4063 // In the bug case, this new entry ends up being a duplicate object pointing |
4064 // at the same underlying files. | 4064 // at the same underlying files. |
4065 disk_cache::Entry* entry3 = NULL; | 4065 disk_cache::Entry* entry3 = NULL; |
4066 EXPECT_EQ(net::OK, OpenEntry(key, &entry3)); | 4066 EXPECT_EQ(net::OK, OpenEntry(key, &entry3)); |
4067 ScopedEntryPtr entry3_closer(entry3); | 4067 ScopedEntryPtr entry3_closer(entry3); |
4068 EXPECT_NE(null, entry3); | 4068 EXPECT_NE(null, entry3); |
4069 | 4069 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4258 entry->Close(); | 4258 entry->Close(); |
4259 | 4259 |
4260 base::RunLoop().RunUntilIdle(); | 4260 base::RunLoop().RunUntilIdle(); |
4261 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); | 4261 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); |
4262 base::RunLoop().RunUntilIdle(); | 4262 base::RunLoop().RunUntilIdle(); |
4263 | 4263 |
4264 EXPECT_TRUE( | 4264 EXPECT_TRUE( |
4265 disk_cache::simple_util::CorruptKeySHA256FromEntry(key, cache_path_)); | 4265 disk_cache::simple_util::CorruptKeySHA256FromEntry(key, cache_path_)); |
4266 EXPECT_NE(net::OK, OpenEntry(key, &entry)); | 4266 EXPECT_NE(net::OK, OpenEntry(key, &entry)); |
4267 } | 4267 } |
OLD | NEW |