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 3188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3199 disk_cache::Entry* entry2 = NULL; | 3199 disk_cache::Entry* entry2 = NULL; |
3200 ASSERT_EQ(net::OK, CreateEntry(key, &entry2)); | 3200 ASSERT_EQ(net::OK, CreateEntry(key, &entry2)); |
3201 ScopedEntryPtr entry2_closer(entry2); | 3201 ScopedEntryPtr entry2_closer(entry2); |
3202 EXPECT_NE(null, entry2); | 3202 EXPECT_NE(null, entry2); |
3203 | 3203 |
3204 entry2->Doom(); | 3204 entry2->Doom(); |
3205 | 3205 |
3206 // This test passes if it doesn't crash. | 3206 // This test passes if it doesn't crash. |
3207 } | 3207 } |
3208 | 3208 |
| 3209 TEST_F(DiskCacheEntryTest, SimpleCacheDoomCloseCreateCloseOpen) { |
| 3210 // Test sequence: Create, Doom, Close, Create, Close, Open. |
| 3211 SetSimpleCacheMode(); |
| 3212 InitCache(); |
| 3213 |
| 3214 disk_cache::Entry* null = NULL; |
| 3215 |
| 3216 const char key[] = "this is a key"; |
| 3217 |
| 3218 disk_cache::Entry* entry1 = NULL; |
| 3219 ASSERT_EQ(net::OK, CreateEntry(key, &entry1)); |
| 3220 ScopedEntryPtr entry1_closer(entry1); |
| 3221 EXPECT_NE(null, entry1); |
| 3222 |
| 3223 entry1->Doom(); |
| 3224 entry1_closer.reset(); |
| 3225 entry1 = NULL; |
| 3226 |
| 3227 disk_cache::Entry* entry2 = NULL; |
| 3228 ASSERT_EQ(net::OK, CreateEntry(key, &entry2)); |
| 3229 ScopedEntryPtr entry2_closer(entry2); |
| 3230 EXPECT_NE(null, entry2); |
| 3231 |
| 3232 entry2_closer.reset(); |
| 3233 entry2 = NULL; |
| 3234 |
| 3235 disk_cache::Entry* entry3 = NULL; |
| 3236 ASSERT_EQ(net::OK, OpenEntry(key, &entry3)); |
| 3237 ScopedEntryPtr entry3_closer(entry3); |
| 3238 EXPECT_NE(null, entry3); |
| 3239 } |
| 3240 |
3209 // Checks that an optimistic Create would fail later on a racing Open. | 3241 // Checks that an optimistic Create would fail later on a racing Open. |
3210 TEST_F(DiskCacheEntryTest, SimpleCacheOptimisticCreateFailsOnOpen) { | 3242 TEST_F(DiskCacheEntryTest, SimpleCacheOptimisticCreateFailsOnOpen) { |
3211 SetSimpleCacheMode(); | 3243 SetSimpleCacheMode(); |
3212 InitCache(); | 3244 InitCache(); |
3213 | 3245 |
3214 // Create a corrupt file in place of a future entry. Optimistic create should | 3246 // Create a corrupt file in place of a future entry. Optimistic create should |
3215 // initially succeed, but realize later that creation failed. | 3247 // initially succeed, but realize later that creation failed. |
3216 const std::string key = "the key"; | 3248 const std::string key = "the key"; |
3217 net::TestCompletionCallback cb; | 3249 net::TestCompletionCallback cb; |
3218 disk_cache::Entry* entry = NULL; | 3250 disk_cache::Entry* entry = NULL; |
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3989 EXPECT_EQ(kSize, callback.GetResult(ret)); | 4021 EXPECT_EQ(kSize, callback.GetResult(ret)); |
3990 | 4022 |
3991 // Make sure the first range was removed when the second was written. | 4023 // Make sure the first range was removed when the second was written. |
3992 ret = entry->ReadSparseData(0, buffer, kSize, callback.callback()); | 4024 ret = entry->ReadSparseData(0, buffer, kSize, callback.callback()); |
3993 EXPECT_EQ(0, callback.GetResult(ret)); | 4025 EXPECT_EQ(0, callback.GetResult(ret)); |
3994 | 4026 |
3995 entry->Close(); | 4027 entry->Close(); |
3996 } | 4028 } |
3997 | 4029 |
3998 #endif // defined(OS_POSIX) | 4030 #endif // defined(OS_POSIX) |
OLD | NEW |