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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 3919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3930 entry->Close(); | 3930 entry->Close(); |
3931 | 3931 |
3932 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); | 3932 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); |
3933 EXPECT_NE(null, entry); | 3933 EXPECT_NE(null, entry); |
3934 | 3934 |
3935 entry->Close(); | 3935 entry->Close(); |
3936 entry = NULL; | 3936 entry = NULL; |
3937 } | 3937 } |
3938 } | 3938 } |
3939 | 3939 |
| 3940 // Tests for a regression in crbug.com/317138 , in which deleting an already |
| 3941 // doomed entry was removing the active entry from the index. |
| 3942 TEST_F(DiskCacheEntryTest, SimpleCachePreserveActiveEntries) { |
| 3943 SetSimpleCacheMode(); |
| 3944 InitCache(); |
| 3945 |
| 3946 disk_cache::Entry* null = NULL; |
| 3947 |
| 3948 const char key[] = "this is a key"; |
| 3949 |
| 3950 disk_cache::Entry* entry1 = NULL; |
| 3951 ASSERT_EQ(net::OK, CreateEntry(key, &entry1)); |
| 3952 ScopedEntryPtr entry1_closer(entry1); |
| 3953 EXPECT_NE(null, entry1); |
| 3954 entry1->Doom(); |
| 3955 |
| 3956 disk_cache::Entry* entry2 = NULL; |
| 3957 ASSERT_EQ(net::OK, CreateEntry(key, &entry2)); |
| 3958 ScopedEntryPtr entry2_closer(entry2); |
| 3959 EXPECT_NE(null, entry2); |
| 3960 entry2_closer.reset(); |
| 3961 |
| 3962 // Closing then reopening entry2 insures that entry2 is serialized, and so |
| 3963 // it can be opened from files without error. |
| 3964 entry2 = NULL; |
| 3965 ASSERT_EQ(net::OK, OpenEntry(key, &entry2)); |
| 3966 EXPECT_NE(null, entry2); |
| 3967 entry2_closer.reset(entry2); |
| 3968 |
| 3969 scoped_refptr<disk_cache::SimpleEntryImpl> |
| 3970 entry1_refptr = static_cast<disk_cache::SimpleEntryImpl*>(entry1); |
| 3971 |
| 3972 // If crbug.com/317138 has regressed, this will remove |entry2| from |
| 3973 // the backend's |active_entries_| while |entry2| is still alive and its |
| 3974 // files are still on disk. |
| 3975 entry1_closer.reset(); |
| 3976 entry1 = NULL; |
| 3977 |
| 3978 // Close does not have a callback. However, we need to be sure the close is |
| 3979 // finished before we continue the test. We can take advantage of how the ref |
| 3980 // counting of a SimpleEntryImpl works to fake out a callback: When the |
| 3981 // last Close() call is made to an entry, an IO operation is sent to the |
| 3982 // synchronous entry to close the platform files. This IO operation holds a |
| 3983 // ref pointer to the entry, which expires when the operation is done. So, |
| 3984 // we take a refpointer, and watch the SimpleEntry object until it has only |
| 3985 // one ref; this indicates the IO operation is complete. |
| 3986 while (!entry1_refptr->HasOneRef()) { |
| 3987 base::PlatformThread::YieldCurrentThread(); |
| 3988 base::MessageLoop::current()->RunUntilIdle(); |
| 3989 } |
| 3990 entry1_refptr = NULL; |
| 3991 |
| 3992 // In the bug case, this new entry ends up being a duplicate object pointing |
| 3993 // at the same underlying files. |
| 3994 disk_cache::Entry* entry3 = NULL; |
| 3995 EXPECT_EQ(net::OK, OpenEntry(key, &entry3)); |
| 3996 ScopedEntryPtr entry3_closer(entry3); |
| 3997 EXPECT_NE(null, entry3); |
| 3998 |
| 3999 // The test passes if these two dooms do not crash. |
| 4000 entry2->Doom(); |
| 4001 entry3->Doom(); |
| 4002 } |
| 4003 |
3940 TEST_F(DiskCacheEntryTest, SimpleCacheBasicSparseIO) { | 4004 TEST_F(DiskCacheEntryTest, SimpleCacheBasicSparseIO) { |
3941 SetSimpleCacheMode(); | 4005 SetSimpleCacheMode(); |
3942 InitCache(); | 4006 InitCache(); |
3943 BasicSparseIO(); | 4007 BasicSparseIO(); |
3944 } | 4008 } |
3945 | 4009 |
3946 TEST_F(DiskCacheEntryTest, SimpleCacheHugeSparseIO) { | 4010 TEST_F(DiskCacheEntryTest, SimpleCacheHugeSparseIO) { |
3947 SetSimpleCacheMode(); | 4011 SetSimpleCacheMode(); |
3948 InitCache(); | 4012 InitCache(); |
3949 HugeSparseIO(); | 4013 HugeSparseIO(); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4021 EXPECT_EQ(kSize, callback.GetResult(ret)); | 4085 EXPECT_EQ(kSize, callback.GetResult(ret)); |
4022 | 4086 |
4023 // Make sure the first range was removed when the second was written. | 4087 // Make sure the first range was removed when the second was written. |
4024 ret = entry->ReadSparseData(0, buffer, kSize, callback.callback()); | 4088 ret = entry->ReadSparseData(0, buffer, kSize, callback.callback()); |
4025 EXPECT_EQ(0, callback.GetResult(ret)); | 4089 EXPECT_EQ(0, callback.GetResult(ret)); |
4026 | 4090 |
4027 entry->Close(); | 4091 entry->Close(); |
4028 } | 4092 } |
4029 | 4093 |
4030 #endif // defined(OS_POSIX) | 4094 #endif // defined(OS_POSIX) |
OLD | NEW |