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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 2890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2901 | 2901 |
2902 EXPECT_EQ(net::ERR_IO_PENDING, | 2902 EXPECT_EQ(net::ERR_IO_PENDING, |
2903 entry->ReadData(0, 0, buffer1.get(), kSize1, cb.callback())); | 2903 entry->ReadData(0, 0, buffer1.get(), kSize1, cb.callback())); |
2904 EXPECT_EQ(kSize1, cb.GetResult(net::ERR_IO_PENDING)); | 2904 EXPECT_EQ(kSize1, cb.GetResult(net::ERR_IO_PENDING)); |
2905 | 2905 |
2906 // Check that we are not leaking. | 2906 // Check that we are not leaking. |
2907 EXPECT_TRUE( | 2907 EXPECT_TRUE( |
2908 static_cast<disk_cache::SimpleEntryImpl*>(entry)->HasOneRef()); | 2908 static_cast<disk_cache::SimpleEntryImpl*>(entry)->HasOneRef()); |
2909 } | 2909 } |
2910 | 2910 |
2911 // TODO(gavinp): Fix this, perhaps by landing | 2911 TEST_F(DiskCacheEntryTest, SimpleCacheOptimistic6) { |
2912 // https://codereview.chromium.org/23823002/ | |
2913 TEST_F(DiskCacheEntryTest, DISABLED_SimpleCacheOptimistic6) { | |
2914 // Test sequence: | 2912 // Test sequence: |
2915 // Create, Write, Doom, Doom, Read, Doom, Close. | 2913 // Create, Write, Doom, Doom, Read, Doom, Close. |
2916 SetSimpleCacheMode(); | 2914 SetSimpleCacheMode(); |
2917 InitCache(); | 2915 InitCache(); |
2918 disk_cache::Entry* null = NULL; | 2916 disk_cache::Entry* null = NULL; |
2919 const char key[] = "the first key"; | 2917 const char key[] = "the first key"; |
2920 | 2918 |
2921 net::TestCompletionCallback cb; | 2919 net::TestCompletionCallback cb; |
2922 const int kSize1 = 10; | 2920 const int kSize1 = 10; |
2923 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize1)); | 2921 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize1)); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3046 cache_->DoomEntry(key, doom_callback.callback())); | 3044 cache_->DoomEntry(key, doom_callback.callback())); |
3047 | 3045 |
3048 disk_cache::Entry* entry2 = NULL; | 3046 disk_cache::Entry* entry2 = NULL; |
3049 ASSERT_EQ(net::OK, | 3047 ASSERT_EQ(net::OK, |
3050 create_callback.GetResult( | 3048 create_callback.GetResult( |
3051 cache_->CreateEntry(key, &entry2, create_callback.callback()))); | 3049 cache_->CreateEntry(key, &entry2, create_callback.callback()))); |
3052 ScopedEntryPtr entry2_closer(entry2); | 3050 ScopedEntryPtr entry2_closer(entry2); |
3053 EXPECT_EQ(net::OK, doom_callback.GetResult(net::ERR_IO_PENDING)); | 3051 EXPECT_EQ(net::OK, doom_callback.GetResult(net::ERR_IO_PENDING)); |
3054 } | 3052 } |
3055 | 3053 |
| 3054 TEST_F(DiskCacheEntryTest, SimpleCacheDoomDoom) { |
| 3055 // Test sequence: |
| 3056 // Create, Doom, Create, Doom (1st entry), Open. |
| 3057 SetSimpleCacheMode(); |
| 3058 InitCache(); |
| 3059 disk_cache::Entry* null = NULL; |
| 3060 |
| 3061 const char key[] = "the first key"; |
| 3062 |
| 3063 disk_cache::Entry* entry1 = NULL; |
| 3064 ASSERT_EQ(net::OK, CreateEntry(key, &entry1)); |
| 3065 ScopedEntryPtr entry1_closer(entry1); |
| 3066 EXPECT_NE(null, entry1); |
| 3067 |
| 3068 EXPECT_EQ(net::OK, DoomEntry(key)); |
| 3069 |
| 3070 disk_cache::Entry* entry2 = NULL; |
| 3071 ASSERT_EQ(net::OK, CreateEntry(key, &entry2)); |
| 3072 ScopedEntryPtr entry2_closer(entry2); |
| 3073 EXPECT_NE(null, entry2); |
| 3074 |
| 3075 // Redundantly dooming entry1 should not delete entry2. |
| 3076 disk_cache::SimpleEntryImpl* simple_entry1 = |
| 3077 static_cast<disk_cache::SimpleEntryImpl*>(entry1); |
| 3078 net::TestCompletionCallback cb; |
| 3079 EXPECT_EQ(net::OK, |
| 3080 cb.GetResult(simple_entry1->DoomEntry(cb.callback()))); |
| 3081 |
| 3082 disk_cache::Entry* entry3 = NULL; |
| 3083 ASSERT_EQ(net::OK, OpenEntry(key, &entry3)); |
| 3084 ScopedEntryPtr entry3_closer(entry3); |
| 3085 EXPECT_NE(null, entry3); |
| 3086 } |
| 3087 |
3056 // Checks that an optimistic Create would fail later on a racing Open. | 3088 // Checks that an optimistic Create would fail later on a racing Open. |
3057 TEST_F(DiskCacheEntryTest, SimpleCacheOptimisticCreateFailsOnOpen) { | 3089 TEST_F(DiskCacheEntryTest, SimpleCacheOptimisticCreateFailsOnOpen) { |
3058 SetSimpleCacheMode(); | 3090 SetSimpleCacheMode(); |
3059 InitCache(); | 3091 InitCache(); |
3060 | 3092 |
3061 // Create a corrupt file in place of a future entry. Optimistic create should | 3093 // Create a corrupt file in place of a future entry. Optimistic create should |
3062 // initially succeed, but realize later that creation failed. | 3094 // initially succeed, but realize later that creation failed. |
3063 const std::string key = "the key"; | 3095 const std::string key = "the key"; |
3064 net::TestCompletionCallback cb; | 3096 net::TestCompletionCallback cb; |
3065 disk_cache::Entry* entry = NULL; | 3097 disk_cache::Entry* entry = NULL; |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3417 | 3449 |
3418 // Check that we are not leaking. | 3450 // Check that we are not leaking. |
3419 ASSERT_NE(entry, null); | 3451 ASSERT_NE(entry, null); |
3420 EXPECT_TRUE( | 3452 EXPECT_TRUE( |
3421 static_cast<disk_cache::SimpleEntryImpl*>(entry)->HasOneRef()); | 3453 static_cast<disk_cache::SimpleEntryImpl*>(entry)->HasOneRef()); |
3422 entry->Close(); | 3454 entry->Close(); |
3423 entry = NULL; | 3455 entry = NULL; |
3424 } | 3456 } |
3425 | 3457 |
3426 #endif // defined(OS_POSIX) | 3458 #endif // defined(OS_POSIX) |
OLD | NEW |