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. | |
pasko
2013/09/12 10:46:48
do we want more sequences like that in the followi
gavinp
2013/09/12 15:39:48
I'm not sure.
| |
3057 SetSimpleCacheMode(); | |
3058 InitCache(); | |
3059 disk_cache::Entry* null = NULL; | |
3060 | |
3061 const char key[] = "the first key"; | |
3062 | |
3063 net::TestCompletionCallback cb; | |
3064 disk_cache::Entry* entry1 = NULL; | |
3065 ASSERT_EQ(net::OK, | |
3066 cb.GetResult(cache_->CreateEntry(key, &entry1, cb.callback()))); | |
pasko
2013/09/12 10:46:48
The common style in all disk_cache testing is to w
gavinp
2013/09/12 15:39:48
Done.
| |
3067 ScopedEntryPtr entry1_closer(entry1); | |
3068 EXPECT_NE(null, entry1); | |
3069 | |
3070 EXPECT_EQ(net::OK, | |
3071 cb.GetResult(cache_->DoomEntry(key, cb.callback()))); | |
3072 | |
3073 disk_cache::Entry* entry2 = NULL; | |
3074 ASSERT_EQ(net::OK, | |
3075 cb.GetResult(cache_->CreateEntry(key, &entry2, cb.callback()))); | |
3076 ScopedEntryPtr entry2_closer(entry2); | |
3077 EXPECT_NE(null, entry2); | |
3078 | |
3079 disk_cache::SimpleEntryImpl* simple_entry1 = | |
3080 static_cast<disk_cache::SimpleEntryImpl*>(entry1); | |
pasko
2013/09/12 10:46:48
why casting? could you just call Doom() on the ent
gavinp
2013/09/12 15:39:48
I want to wait for the callback, so I know this do
| |
3081 EXPECT_EQ(net::OK, | |
3082 cb.GetResult(simple_entry1->DoomEntry(cb.callback()))); | |
3083 | |
3084 disk_cache::Entry* entry3 = NULL; | |
3085 ASSERT_EQ(net::OK, | |
3086 cb.GetResult(cache_->OpenEntry(key, &entry3, cb.callback()))); | |
3087 ScopedEntryPtr entry3_closer(entry3); | |
3088 EXPECT_NE(null, entry3); | |
3089 } | |
3090 | |
3056 // Checks that an optimistic Create would fail later on a racing Open. | 3091 // Checks that an optimistic Create would fail later on a racing Open. |
3057 TEST_F(DiskCacheEntryTest, SimpleCacheOptimisticCreateFailsOnOpen) { | 3092 TEST_F(DiskCacheEntryTest, SimpleCacheOptimisticCreateFailsOnOpen) { |
3058 SetSimpleCacheMode(); | 3093 SetSimpleCacheMode(); |
3059 InitCache(); | 3094 InitCache(); |
3060 | 3095 |
3061 // Create a corrupt file in place of a future entry. Optimistic create should | 3096 // Create a corrupt file in place of a future entry. Optimistic create should |
3062 // initially succeed, but realize later that creation failed. | 3097 // initially succeed, but realize later that creation failed. |
3063 const std::string key = "the key"; | 3098 const std::string key = "the key"; |
3064 net::TestCompletionCallback cb; | 3099 net::TestCompletionCallback cb; |
3065 disk_cache::Entry* entry = NULL; | 3100 disk_cache::Entry* entry = NULL; |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3417 | 3452 |
3418 // Check that we are not leaking. | 3453 // Check that we are not leaking. |
3419 ASSERT_NE(entry, null); | 3454 ASSERT_NE(entry, null); |
3420 EXPECT_TRUE( | 3455 EXPECT_TRUE( |
3421 static_cast<disk_cache::SimpleEntryImpl*>(entry)->HasOneRef()); | 3456 static_cast<disk_cache::SimpleEntryImpl*>(entry)->HasOneRef()); |
3422 entry->Close(); | 3457 entry->Close(); |
3423 entry = NULL; | 3458 entry = NULL; |
3424 } | 3459 } |
3425 | 3460 |
3426 #endif // defined(OS_POSIX) | 3461 #endif // defined(OS_POSIX) |
OLD | NEW |