Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(792)

Side by Side Diff: net/disk_cache/backend_unittest.cc

Issue 3387012: Revert 60165 - GTTF: Make net_unittests run successfully with parallel test l... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/disk_cache/block_files_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2010 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/file_util.h" 6 #include "base/file_util.h"
7 #include "base/platform_thread.h" 7 #include "base/platform_thread.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 SetMemoryOnlyMode(); 173 SetMemoryOnlyMode();
174 BackendKeying(); 174 BackendKeying();
175 } 175 }
176 176
177 TEST_F(DiskCacheBackendTest, AppCacheKeying) { 177 TEST_F(DiskCacheBackendTest, AppCacheKeying) {
178 SetCacheType(net::APP_CACHE); 178 SetCacheType(net::APP_CACHE);
179 BackendKeying(); 179 BackendKeying();
180 } 180 }
181 181
182 TEST_F(DiskCacheTest, CreateBackend) { 182 TEST_F(DiskCacheTest, CreateBackend) {
183 ScopedTestCache test_cache;
184 TestCompletionCallback cb; 183 TestCompletionCallback cb;
185 184
186 { 185 {
186 FilePath path = GetCacheFilePath();
187 ASSERT_TRUE(DeleteCache(path));
187 base::Thread cache_thread("CacheThread"); 188 base::Thread cache_thread("CacheThread");
188 ASSERT_TRUE(cache_thread.StartWithOptions( 189 ASSERT_TRUE(cache_thread.StartWithOptions(
189 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 190 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
190 191
191 // Test the private factory methods. 192 // Test the private factory methods.
192 disk_cache::Backend* cache = NULL; 193 disk_cache::Backend* cache = NULL;
193 int rv = disk_cache::BackendImpl::CreateBackend( 194 int rv = disk_cache::BackendImpl::CreateBackend(
194 test_cache.path(), false, 0, net::DISK_CACHE, disk_cache::kNoRandom, 195 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
195 cache_thread.message_loop_proxy(), &cache, &cb); 196 cache_thread.message_loop_proxy(), &cache, &cb);
196 ASSERT_EQ(net::OK, cb.GetResult(rv)); 197 ASSERT_EQ(net::OK, cb.GetResult(rv));
197 ASSERT_TRUE(cache); 198 ASSERT_TRUE(cache);
198 delete cache; 199 delete cache;
199 200
200 cache = disk_cache::MemBackendImpl::CreateBackend(0); 201 cache = disk_cache::MemBackendImpl::CreateBackend(0);
201 ASSERT_TRUE(cache); 202 ASSERT_TRUE(cache);
202 delete cache; 203 delete cache;
203 cache = NULL; 204 cache = NULL;
204 205
205 // Now test the public API. 206 // Now test the public API.
206 rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, test_cache.path(), 207 rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false,
207 0, false,
208 cache_thread.message_loop_proxy(), 208 cache_thread.message_loop_proxy(),
209 &cache, &cb); 209 &cache, &cb);
210 ASSERT_EQ(net::OK, cb.GetResult(rv)); 210 ASSERT_EQ(net::OK, cb.GetResult(rv));
211 ASSERT_TRUE(cache); 211 ASSERT_TRUE(cache);
212 delete cache; 212 delete cache;
213 cache = NULL; 213 cache = NULL;
214 214
215 rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE, FilePath(), 0, false, 215 rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE, FilePath(), 0, false,
216 NULL, &cache, &cb); 216 NULL, &cache, &cb);
217 ASSERT_EQ(net::OK, cb.GetResult(rv)); 217 ASSERT_EQ(net::OK, cb.GetResult(rv));
218 ASSERT_TRUE(cache); 218 ASSERT_TRUE(cache);
219 delete cache; 219 delete cache;
220 } 220 }
221 221
222 MessageLoop::current()->RunAllPending(); 222 MessageLoop::current()->RunAllPending();
223 } 223 }
224 224
225 TEST_F(DiskCacheBackendTest, ExternalFiles) { 225 TEST_F(DiskCacheBackendTest, ExternalFiles) {
226 InitCache(); 226 InitCache();
227 // First, lets create a file on the folder. 227 // First, lets create a file on the folder.
228 FilePath filename = path().AppendASCII("f_000001"); 228 FilePath filename = GetCacheFilePath().AppendASCII("f_000001");
229 229
230 const int kSize = 50; 230 const int kSize = 50;
231 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); 231 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize);
232 CacheTestFillBuffer(buffer1->data(), kSize, false); 232 CacheTestFillBuffer(buffer1->data(), kSize, false);
233 ASSERT_EQ(kSize, file_util::WriteFile(filename, buffer1->data(), kSize)); 233 ASSERT_EQ(kSize, file_util::WriteFile(filename, buffer1->data(), kSize));
234 234
235 // Now let's create a file with the cache. 235 // Now let's create a file with the cache.
236 disk_cache::Entry* entry; 236 disk_cache::Entry* entry;
237 ASSERT_EQ(net::OK, CreateEntry("key", &entry)); 237 ASSERT_EQ(net::OK, CreateEntry("key", &entry));
238 ASSERT_EQ(0, WriteData(entry, 0, 20000, buffer1, 0, false)); 238 ASSERT_EQ(0, WriteData(entry, 0, 20000, buffer1, 0, false));
239 entry->Close(); 239 entry->Close();
240 240
241 // And verify that the first file is still there. 241 // And verify that the first file is still there.
242 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize); 242 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize);
243 ASSERT_EQ(kSize, file_util::ReadFile(filename, buffer2->data(), kSize)); 243 ASSERT_EQ(kSize, file_util::ReadFile(filename, buffer2->data(), kSize));
244 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize)); 244 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize));
245 } 245 }
246 246
247 // Tests that we deal with file-level pending operations at destruction time. 247 // Tests that we deal with file-level pending operations at destruction time.
248 TEST_F(DiskCacheTest, ShutdownWithPendingIO) { 248 TEST_F(DiskCacheTest, ShutdownWithPendingIO) {
249 ScopedTestCache test_cache;
250 TestCompletionCallback cb; 249 TestCompletionCallback cb;
251 250
252 { 251 {
252 FilePath path = GetCacheFilePath();
253 ASSERT_TRUE(DeleteCache(path));
253 base::Thread cache_thread("CacheThread"); 254 base::Thread cache_thread("CacheThread");
254 ASSERT_TRUE(cache_thread.StartWithOptions( 255 ASSERT_TRUE(cache_thread.StartWithOptions(
255 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 256 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
256 257
257 disk_cache::Backend* cache; 258 disk_cache::Backend* cache;
258 int rv = disk_cache::BackendImpl::CreateBackend( 259 int rv = disk_cache::BackendImpl::CreateBackend(
259 test_cache.path(), false, 0, net::DISK_CACHE, disk_cache::kNoRandom, 260 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
260 base::MessageLoopProxy::CreateForCurrentThread(), &cache, &cb); 261 base::MessageLoopProxy::CreateForCurrentThread(), &cache, &cb);
261 ASSERT_EQ(net::OK, cb.GetResult(rv)); 262 ASSERT_EQ(net::OK, cb.GetResult(rv));
262 263
263 disk_cache::EntryImpl* entry; 264 disk_cache::EntryImpl* entry;
264 rv = cache->CreateEntry("some key", 265 rv = cache->CreateEntry("some key",
265 reinterpret_cast<disk_cache::Entry**>(&entry), &cb); 266 reinterpret_cast<disk_cache::Entry**>(&entry), &cb);
266 ASSERT_EQ(net::OK, cb.GetResult(rv)); 267 ASSERT_EQ(net::OK, cb.GetResult(rv));
267 268
268 const int kSize = 25000; 269 const int kSize = 25000;
269 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); 270 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize);
270 CacheTestFillBuffer(buffer->data(), kSize, false); 271 CacheTestFillBuffer(buffer->data(), kSize, false);
(...skipping 18 matching lines...) Expand all
289 if (rv == net::ERR_IO_PENDING) { 290 if (rv == net::ERR_IO_PENDING) {
290 EXPECT_TRUE(cb.have_result()); 291 EXPECT_TRUE(cb.have_result());
291 } 292 }
292 } 293 }
293 294
294 MessageLoop::current()->RunAllPending(); 295 MessageLoop::current()->RunAllPending();
295 } 296 }
296 297
297 // Tests that we deal with background-thread pending operations. 298 // Tests that we deal with background-thread pending operations.
298 TEST_F(DiskCacheTest, ShutdownWithPendingIO2) { 299 TEST_F(DiskCacheTest, ShutdownWithPendingIO2) {
299 ScopedTestCache test_cache;
300 TestCompletionCallback cb; 300 TestCompletionCallback cb;
301 301
302 { 302 {
303 FilePath path = GetCacheFilePath();
304 ASSERT_TRUE(DeleteCache(path));
303 base::Thread cache_thread("CacheThread"); 305 base::Thread cache_thread("CacheThread");
304 ASSERT_TRUE(cache_thread.StartWithOptions( 306 ASSERT_TRUE(cache_thread.StartWithOptions(
305 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 307 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
306 308
307 disk_cache::Backend* cache; 309 disk_cache::Backend* cache;
308 int rv = disk_cache::BackendImpl::CreateBackend( 310 int rv = disk_cache::BackendImpl::CreateBackend(
309 test_cache.path(), false, 0, net::DISK_CACHE, disk_cache::kNoRandom, 311 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
310 cache_thread.message_loop_proxy(), &cache, &cb); 312 cache_thread.message_loop_proxy(), &cache, &cb);
311 ASSERT_EQ(net::OK, cb.GetResult(rv)); 313 ASSERT_EQ(net::OK, cb.GetResult(rv));
312 314
313 disk_cache::Entry* entry; 315 disk_cache::Entry* entry;
314 rv = cache->CreateEntry("some key", &entry, &cb); 316 rv = cache->CreateEntry("some key", &entry, &cb);
315 ASSERT_EQ(net::OK, cb.GetResult(rv)); 317 ASSERT_EQ(net::OK, cb.GetResult(rv));
316 318
317 const int kSize = 25000; 319 const int kSize = 25000;
318 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); 320 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize);
319 CacheTestFillBuffer(buffer->data(), kSize, false); 321 CacheTestFillBuffer(buffer->data(), kSize, false);
320 322
321 rv = entry->WriteData(0, 0, buffer, kSize, &cb, false); 323 rv = entry->WriteData(0, 0, buffer, kSize, &cb, false);
322 EXPECT_EQ(net::ERR_IO_PENDING, rv); 324 EXPECT_EQ(net::ERR_IO_PENDING, rv);
323 325
324 entry->Close(); 326 entry->Close();
325 327
326 // The cache destructor will see two pending operations here. 328 // The cache destructor will see two pending operations here.
327 delete cache; 329 delete cache;
328 } 330 }
329 331
330 MessageLoop::current()->RunAllPending(); 332 MessageLoop::current()->RunAllPending();
331 } 333 }
332 334
333 TEST_F(DiskCacheTest, TruncatedIndex) { 335 TEST_F(DiskCacheTest, TruncatedIndex) {
334 ScopedTestCache test_cache; 336 FilePath path = GetCacheFilePath();
335 337 ASSERT_TRUE(DeleteCache(path));
336 FilePath index = test_cache.path().AppendASCII("index"); 338 FilePath index = path.AppendASCII("index");
337 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5)); 339 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5));
338 340
339 base::Thread cache_thread("CacheThread"); 341 base::Thread cache_thread("CacheThread");
340 ASSERT_TRUE(cache_thread.StartWithOptions( 342 ASSERT_TRUE(cache_thread.StartWithOptions(
341 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 343 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
342 TestCompletionCallback cb; 344 TestCompletionCallback cb;
343 345
344 disk_cache::Backend* backend = NULL; 346 disk_cache::Backend* backend = NULL;
345 int rv = disk_cache::BackendImpl::CreateBackend( 347 int rv = disk_cache::BackendImpl::CreateBackend(
346 test_cache.path(), false, 0, net::DISK_CACHE, disk_cache::kNone, 348 path, false, 0, net::DISK_CACHE, disk_cache::kNone,
347 cache_thread.message_loop_proxy(), &backend, &cb); 349 cache_thread.message_loop_proxy(), &backend, &cb);
348 ASSERT_NE(net::OK, cb.GetResult(rv)); 350 ASSERT_NE(net::OK, cb.GetResult(rv));
349 351
350 ASSERT_TRUE(backend == NULL); 352 ASSERT_TRUE(backend == NULL);
351 delete backend; 353 delete backend;
352 } 354 }
353 355
354 void DiskCacheBackendTest::BackendSetSize() { 356 void DiskCacheBackendTest::BackendSetSize() {
355 SetDirectMode(); 357 SetDirectMode();
356 const int cache_size = 0x10000; // 64 kB 358 const int cache_size = 0x10000; // 64 kB
357 SetMaxSize(cache_size); 359 SetMaxSize(cache_size);
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 } 1138 }
1137 1139
1138 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomBetween) { 1140 TEST_F(DiskCacheBackendTest, MemoryOnlyDoomBetween) {
1139 SetMemoryOnlyMode(); 1141 SetMemoryOnlyMode();
1140 BackendDoomBetween(); 1142 BackendDoomBetween();
1141 } 1143 }
1142 1144
1143 void DiskCacheBackendTest::BackendTransaction(const std::string& name, 1145 void DiskCacheBackendTest::BackendTransaction(const std::string& name,
1144 int num_entries, bool load) { 1146 int num_entries, bool load) {
1145 success_ = false; 1147 success_ = false;
1146 ASSERT_TRUE(CopyTestCache(name, path())); 1148 ASSERT_TRUE(CopyTestCache(name));
1147 DisableFirstCleanup(); 1149 DisableFirstCleanup();
1148 1150
1149 if (load) { 1151 if (load) {
1150 SetMask(0xf); 1152 SetMask(0xf);
1151 SetMaxSize(0x100000); 1153 SetMaxSize(0x100000);
1152 } else { 1154 } else {
1153 // Clear the settings from the previous run. 1155 // Clear the settings from the previous run.
1154 SetMask(0); 1156 SetMask(0);
1155 SetMaxSize(0); 1157 SetMaxSize(0);
1156 } 1158 }
(...skipping 10 matching lines...) Expand all
1167 ASSERT_TRUE(load); 1169 ASSERT_TRUE(load);
1168 // If there is a heavy load, inserting an entry will make another entry 1170 // If there is a heavy load, inserting an entry will make another entry
1169 // dirty (on the hash bucket) so two entries are removed. 1171 // dirty (on the hash bucket) so two entries are removed.
1170 ASSERT_EQ(num_entries - 1, actual); 1172 ASSERT_EQ(num_entries - 1, actual);
1171 } 1173 }
1172 1174
1173 delete cache_; 1175 delete cache_;
1174 cache_ = NULL; 1176 cache_ = NULL;
1175 cache_impl_ = NULL; 1177 cache_impl_ = NULL;
1176 1178
1177 ASSERT_TRUE(CheckCacheIntegrity(path(), new_eviction_)); 1179 ASSERT_TRUE(CheckCacheIntegrity(GetCacheFilePath(), new_eviction_));
1178 success_ = true; 1180 success_ = true;
1179 } 1181 }
1180 1182
1181 void DiskCacheBackendTest::BackendRecoverInsert() { 1183 void DiskCacheBackendTest::BackendRecoverInsert() {
1182 // Tests with an empty cache. 1184 // Tests with an empty cache.
1183 BackendTransaction("insert_empty1", 0, false); 1185 BackendTransaction("insert_empty1", 0, false);
1184 ASSERT_TRUE(success_) << "insert_empty1"; 1186 ASSERT_TRUE(success_) << "insert_empty1";
1185 BackendTransaction("insert_empty2", 0, false); 1187 BackendTransaction("insert_empty2", 0, false);
1186 ASSERT_TRUE(success_) << "insert_empty2"; 1188 ASSERT_TRUE(success_) << "insert_empty2";
1187 BackendTransaction("insert_empty3", 0, false); 1189 BackendTransaction("insert_empty3", 0, false);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 BackendRecoverRemove(); 1259 BackendRecoverRemove();
1258 } 1260 }
1259 1261
1260 TEST_F(DiskCacheBackendTest, NewEvictionRecoverRemove) { 1262 TEST_F(DiskCacheBackendTest, NewEvictionRecoverRemove) {
1261 SetNewEviction(); 1263 SetNewEviction();
1262 BackendRecoverRemove(); 1264 BackendRecoverRemove();
1263 } 1265 }
1264 1266
1265 // Tests dealing with cache files that cannot be recovered. 1267 // Tests dealing with cache files that cannot be recovered.
1266 TEST_F(DiskCacheTest, DeleteOld) { 1268 TEST_F(DiskCacheTest, DeleteOld) {
1267 ScopedTestCache test_cache; 1269 ASSERT_TRUE(CopyTestCache("wrong_version"));
1268 1270 FilePath path = GetCacheFilePath();
1269 ASSERT_TRUE(CopyTestCache("wrong_version", test_cache.path()));
1270 base::Thread cache_thread("CacheThread"); 1271 base::Thread cache_thread("CacheThread");
1271 ASSERT_TRUE(cache_thread.StartWithOptions( 1272 ASSERT_TRUE(cache_thread.StartWithOptions(
1272 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 1273 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
1273 TestCompletionCallback cb; 1274 TestCompletionCallback cb;
1274 1275
1275 disk_cache::Backend* cache; 1276 disk_cache::Backend* cache;
1276 int rv = disk_cache::BackendImpl::CreateBackend( 1277 int rv = disk_cache::BackendImpl::CreateBackend(
1277 test_cache.path(), true, 0, net::DISK_CACHE, disk_cache::kNoRandom, 1278 path, true, 0, net::DISK_CACHE, disk_cache::kNoRandom,
1278 cache_thread.message_loop_proxy(), &cache, &cb); 1279 cache_thread.message_loop_proxy(), &cache, &cb);
1279 ASSERT_EQ(net::OK, cb.GetResult(rv)); 1280 ASSERT_EQ(net::OK, cb.GetResult(rv));
1280 1281
1281 MessageLoopHelper helper; 1282 MessageLoopHelper helper;
1282 1283
1283 ASSERT_TRUE(NULL != cache); 1284 ASSERT_TRUE(NULL != cache);
1284 ASSERT_EQ(0, cache->GetEntryCount()); 1285 ASSERT_EQ(0, cache->GetEntryCount());
1285 1286
1286 delete cache; 1287 delete cache;
1287 } 1288 }
1288 1289
1289 // We want to be able to deal with messed up entries on disk. 1290 // We want to be able to deal with messed up entries on disk.
1290 void DiskCacheBackendTest::BackendInvalidEntry2() { 1291 void DiskCacheBackendTest::BackendInvalidEntry2() {
1291 ASSERT_TRUE(CopyTestCache("bad_entry", path())); 1292 ASSERT_TRUE(CopyTestCache("bad_entry"));
1292 DisableFirstCleanup(); 1293 DisableFirstCleanup();
1293 InitCache(); 1294 InitCache();
1294 1295
1295 disk_cache::Entry *entry1, *entry2; 1296 disk_cache::Entry *entry1, *entry2;
1296 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1)); 1297 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1));
1297 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2)); 1298 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2));
1298 entry1->Close(); 1299 entry1->Close();
1299 1300
1300 // CheckCacheIntegrity will fail at this point. 1301 // CheckCacheIntegrity will fail at this point.
1301 DisableIntegrityCheck(); 1302 DisableIntegrityCheck();
1302 } 1303 }
1303 1304
1304 TEST_F(DiskCacheBackendTest, InvalidEntry2) { 1305 TEST_F(DiskCacheBackendTest, InvalidEntry2) {
1305 BackendInvalidEntry2(); 1306 BackendInvalidEntry2();
1306 } 1307 }
1307 1308
1308 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry2) { 1309 TEST_F(DiskCacheBackendTest, NewEvictionInvalidEntry2) {
1309 SetNewEviction(); 1310 SetNewEviction();
1310 BackendInvalidEntry2(); 1311 BackendInvalidEntry2();
1311 } 1312 }
1312 1313
1313 // We want to be able to deal with abnormal dirty entries. 1314 // We want to be able to deal with abnormal dirty entries.
1314 void DiskCacheBackendTest::BackendNotMarkedButDirty(const std::string& name) { 1315 void DiskCacheBackendTest::BackendNotMarkedButDirty(const std::string& name) {
1315 ASSERT_TRUE(CopyTestCache(name, path())); 1316 ASSERT_TRUE(CopyTestCache(name));
1316 DisableFirstCleanup(); 1317 DisableFirstCleanup();
1317 InitCache(); 1318 InitCache();
1318 1319
1319 disk_cache::Entry *entry1, *entry2; 1320 disk_cache::Entry *entry1, *entry2;
1320 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1)); 1321 ASSERT_EQ(net::OK, OpenEntry("the first key", &entry1));
1321 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2)); 1322 EXPECT_NE(net::OK, OpenEntry("some other key", &entry2));
1322 entry1->Close(); 1323 entry1->Close();
1323 } 1324 }
1324 1325
1325 TEST_F(DiskCacheBackendTest, NotMarkedButDirty) { 1326 TEST_F(DiskCacheBackendTest, NotMarkedButDirty) {
1326 BackendNotMarkedButDirty("dirty_entry"); 1327 BackendNotMarkedButDirty("dirty_entry");
1327 } 1328 }
1328 1329
1329 TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty) { 1330 TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty) {
1330 SetNewEviction(); 1331 SetNewEviction();
1331 BackendNotMarkedButDirty("dirty_entry"); 1332 BackendNotMarkedButDirty("dirty_entry");
1332 } 1333 }
1333 1334
1334 TEST_F(DiskCacheBackendTest, NotMarkedButDirty2) { 1335 TEST_F(DiskCacheBackendTest, NotMarkedButDirty2) {
1335 BackendNotMarkedButDirty("dirty_entry2"); 1336 BackendNotMarkedButDirty("dirty_entry2");
1336 } 1337 }
1337 1338
1338 TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty2) { 1339 TEST_F(DiskCacheBackendTest, NewEvictionNotMarkedButDirty2) {
1339 SetNewEviction(); 1340 SetNewEviction();
1340 BackendNotMarkedButDirty("dirty_entry2"); 1341 BackendNotMarkedButDirty("dirty_entry2");
1341 } 1342 }
1342 1343
1343 // We want to be able to deal with messed up entries on disk. 1344 // We want to be able to deal with messed up entries on disk.
1344 void DiskCacheBackendTest::BackendInvalidRankings2() { 1345 void DiskCacheBackendTest::BackendInvalidRankings2() {
1345 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); 1346 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1347 FilePath path = GetCacheFilePath();
1346 DisableFirstCleanup(); 1348 DisableFirstCleanup();
1347 InitCache(); 1349 InitCache();
1348 1350
1349 disk_cache::Entry *entry1, *entry2; 1351 disk_cache::Entry *entry1, *entry2;
1350 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1)); 1352 EXPECT_NE(net::OK, OpenEntry("the first key", &entry1));
1351 ASSERT_EQ(net::OK, OpenEntry("some other key", &entry2)); 1353 ASSERT_EQ(net::OK, OpenEntry("some other key", &entry2));
1352 entry2->Close(); 1354 entry2->Close();
1353 1355
1354 // CheckCacheIntegrity will fail at this point. 1356 // CheckCacheIntegrity will fail at this point.
1355 DisableIntegrityCheck(); 1357 DisableIntegrityCheck();
(...skipping 15 matching lines...) Expand all
1371 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry)); 1373 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry));
1372 entry->Close(); 1374 entry->Close();
1373 EXPECT_EQ(2, cache_->GetEntryCount()); 1375 EXPECT_EQ(2, cache_->GetEntryCount());
1374 1376
1375 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry)); 1377 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry));
1376 FlushQueueForTest(); // Allow the restart to finish. 1378 FlushQueueForTest(); // Allow the restart to finish.
1377 EXPECT_EQ(0, cache_->GetEntryCount()); 1379 EXPECT_EQ(0, cache_->GetEntryCount());
1378 } 1380 }
1379 1381
1380 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { 1382 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) {
1381 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); 1383 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1382 DisableFirstCleanup(); 1384 DisableFirstCleanup();
1383 SetDirectMode(); 1385 SetDirectMode();
1384 InitCache(); 1386 InitCache();
1385 BackendInvalidRankings(); 1387 BackendInvalidRankings();
1386 } 1388 }
1387 1389
1388 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsSuccess) { 1390 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsSuccess) {
1389 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); 1391 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1390 DisableFirstCleanup(); 1392 DisableFirstCleanup();
1391 SetDirectMode(); 1393 SetDirectMode();
1392 SetNewEviction(); 1394 SetNewEviction();
1393 InitCache(); 1395 InitCache();
1394 BackendInvalidRankings(); 1396 BackendInvalidRankings();
1395 } 1397 }
1396 1398
1397 TEST_F(DiskCacheBackendTest, InvalidRankingsFailure) { 1399 TEST_F(DiskCacheBackendTest, InvalidRankingsFailure) {
1398 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); 1400 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1399 DisableFirstCleanup(); 1401 DisableFirstCleanup();
1400 SetDirectMode(); 1402 SetDirectMode();
1401 InitCache(); 1403 InitCache();
1402 SetTestMode(); // Fail cache reinitialization. 1404 SetTestMode(); // Fail cache reinitialization.
1403 BackendInvalidRankings(); 1405 BackendInvalidRankings();
1404 } 1406 }
1405 1407
1406 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsFailure) { 1408 TEST_F(DiskCacheBackendTest, NewEvictionInvalidRankingsFailure) {
1407 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); 1409 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1408 DisableFirstCleanup(); 1410 DisableFirstCleanup();
1409 SetDirectMode(); 1411 SetDirectMode();
1410 SetNewEviction(); 1412 SetNewEviction();
1411 InitCache(); 1413 InitCache();
1412 SetTestMode(); // Fail cache reinitialization. 1414 SetTestMode(); // Fail cache reinitialization.
1413 BackendInvalidRankings(); 1415 BackendInvalidRankings();
1414 } 1416 }
1415 1417
1416 // If the LRU is corrupt and we have open entries, we disable the cache. 1418 // If the LRU is corrupt and we have open entries, we disable the cache.
1417 void DiskCacheBackendTest::BackendDisable() { 1419 void DiskCacheBackendTest::BackendDisable() {
1418 disk_cache::Entry *entry1, *entry2; 1420 disk_cache::Entry *entry1, *entry2;
1419 void* iter = NULL; 1421 void* iter = NULL;
1420 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); 1422 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1));
1421 1423
1422 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); 1424 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2));
1423 EXPECT_EQ(2, cache_->GetEntryCount()); 1425 EXPECT_EQ(2, cache_->GetEntryCount());
1424 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2)); 1426 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2));
1425 1427
1426 entry1->Close(); 1428 entry1->Close();
1427 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. 1429 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache.
1428 FlushQueueForTest(); // This one actually allows that task to complete. 1430 FlushQueueForTest(); // This one actually allows that task to complete.
1429 1431
1430 EXPECT_EQ(0, cache_->GetEntryCount()); 1432 EXPECT_EQ(0, cache_->GetEntryCount());
1431 } 1433 }
1432 1434
1433 TEST_F(DiskCacheBackendTest, DisableSuccess) { 1435 TEST_F(DiskCacheBackendTest, DisableSuccess) {
1434 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); 1436 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1435 DisableFirstCleanup(); 1437 DisableFirstCleanup();
1436 SetDirectMode(); 1438 SetDirectMode();
1437 InitCache(); 1439 InitCache();
1438 BackendDisable(); 1440 BackendDisable();
1439 } 1441 }
1440 1442
1441 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess) { 1443 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess) {
1442 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); 1444 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1443 DisableFirstCleanup(); 1445 DisableFirstCleanup();
1444 SetDirectMode(); 1446 SetDirectMode();
1445 SetNewEviction(); 1447 SetNewEviction();
1446 InitCache(); 1448 InitCache();
1447 BackendDisable(); 1449 BackendDisable();
1448 } 1450 }
1449 1451
1450 TEST_F(DiskCacheBackendTest, DisableFailure) { 1452 TEST_F(DiskCacheBackendTest, DisableFailure) {
1451 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); 1453 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1452 DisableFirstCleanup(); 1454 DisableFirstCleanup();
1453 SetDirectMode(); 1455 SetDirectMode();
1454 InitCache(); 1456 InitCache();
1455 SetTestMode(); // Fail cache reinitialization. 1457 SetTestMode(); // Fail cache reinitialization.
1456 BackendDisable(); 1458 BackendDisable();
1457 } 1459 }
1458 1460
1459 TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure) { 1461 TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure) {
1460 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); 1462 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1461 DisableFirstCleanup(); 1463 DisableFirstCleanup();
1462 SetDirectMode(); 1464 SetDirectMode();
1463 SetNewEviction(); 1465 SetNewEviction();
1464 InitCache(); 1466 InitCache();
1465 SetTestMode(); // Fail cache reinitialization. 1467 SetTestMode(); // Fail cache reinitialization.
1466 BackendDisable(); 1468 BackendDisable();
1467 } 1469 }
1468 1470
1469 // This is another type of corruption on the LRU; disable the cache. 1471 // This is another type of corruption on the LRU; disable the cache.
1470 void DiskCacheBackendTest::BackendDisable2() { 1472 void DiskCacheBackendTest::BackendDisable2() {
1471 EXPECT_EQ(8, cache_->GetEntryCount()); 1473 EXPECT_EQ(8, cache_->GetEntryCount());
1472 1474
1473 disk_cache::Entry* entry; 1475 disk_cache::Entry* entry;
1474 void* iter = NULL; 1476 void* iter = NULL;
1475 int count = 0; 1477 int count = 0;
1476 while (OpenNextEntry(&iter, &entry) == net::OK) { 1478 while (OpenNextEntry(&iter, &entry) == net::OK) {
1477 ASSERT_TRUE(NULL != entry); 1479 ASSERT_TRUE(NULL != entry);
1478 entry->Close(); 1480 entry->Close();
1479 count++; 1481 count++;
1480 ASSERT_LT(count, 9); 1482 ASSERT_LT(count, 9);
1481 }; 1483 };
1482 1484
1483 FlushQueueForTest(); 1485 FlushQueueForTest();
1484 EXPECT_EQ(0, cache_->GetEntryCount()); 1486 EXPECT_EQ(0, cache_->GetEntryCount());
1485 } 1487 }
1486 1488
1487 TEST_F(DiskCacheBackendTest, DisableSuccess2) { 1489 TEST_F(DiskCacheBackendTest, DisableSuccess2) {
1488 ASSERT_TRUE(CopyTestCache("list_loop", path())); 1490 ASSERT_TRUE(CopyTestCache("list_loop"));
1489 DisableFirstCleanup(); 1491 DisableFirstCleanup();
1490 SetDirectMode(); 1492 SetDirectMode();
1491 InitCache(); 1493 InitCache();
1492 BackendDisable2(); 1494 BackendDisable2();
1493 } 1495 }
1494 1496
1495 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess2) { 1497 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess2) {
1496 ASSERT_TRUE(CopyTestCache("list_loop", path())); 1498 ASSERT_TRUE(CopyTestCache("list_loop"));
1497 DisableFirstCleanup(); 1499 DisableFirstCleanup();
1498 SetNewEviction(); 1500 SetNewEviction();
1499 SetDirectMode(); 1501 SetDirectMode();
1500 InitCache(); 1502 InitCache();
1501 BackendDisable2(); 1503 BackendDisable2();
1502 } 1504 }
1503 1505
1504 TEST_F(DiskCacheBackendTest, DisableFailure2) { 1506 TEST_F(DiskCacheBackendTest, DisableFailure2) {
1505 ASSERT_TRUE(CopyTestCache("list_loop", path())); 1507 ASSERT_TRUE(CopyTestCache("list_loop"));
1506 DisableFirstCleanup(); 1508 DisableFirstCleanup();
1507 SetDirectMode(); 1509 SetDirectMode();
1508 InitCache(); 1510 InitCache();
1509 SetTestMode(); // Fail cache reinitialization. 1511 SetTestMode(); // Fail cache reinitialization.
1510 BackendDisable2(); 1512 BackendDisable2();
1511 } 1513 }
1512 1514
1513 TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure2) { 1515 TEST_F(DiskCacheBackendTest, NewEvictionDisableFailure2) {
1514 ASSERT_TRUE(CopyTestCache("list_loop", path())); 1516 ASSERT_TRUE(CopyTestCache("list_loop"));
1515 DisableFirstCleanup(); 1517 DisableFirstCleanup();
1516 SetDirectMode(); 1518 SetDirectMode();
1517 SetNewEviction(); 1519 SetNewEviction();
1518 InitCache(); 1520 InitCache();
1519 SetTestMode(); // Fail cache reinitialization. 1521 SetTestMode(); // Fail cache reinitialization.
1520 BackendDisable2(); 1522 BackendDisable2();
1521 } 1523 }
1522 1524
1523 // If the index size changes when we disable the cache, we should not crash. 1525 // If the index size changes when we disable the cache, we should not crash.
1524 void DiskCacheBackendTest::BackendDisable3() { 1526 void DiskCacheBackendTest::BackendDisable3() {
1525 disk_cache::Entry *entry1, *entry2; 1527 disk_cache::Entry *entry1, *entry2;
1526 void* iter = NULL; 1528 void* iter = NULL;
1527 EXPECT_EQ(2, cache_->GetEntryCount()); 1529 EXPECT_EQ(2, cache_->GetEntryCount());
1528 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); 1530 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1));
1529 entry1->Close(); 1531 entry1->Close();
1530 1532
1531 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); 1533 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2));
1532 FlushQueueForTest(); 1534 FlushQueueForTest();
1533 1535
1534 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2)); 1536 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2));
1535 entry2->Close(); 1537 entry2->Close();
1536 1538
1537 EXPECT_EQ(1, cache_->GetEntryCount()); 1539 EXPECT_EQ(1, cache_->GetEntryCount());
1538 } 1540 }
1539 1541
1540 TEST_F(DiskCacheBackendTest, DisableSuccess3) { 1542 TEST_F(DiskCacheBackendTest, DisableSuccess3) {
1541 ASSERT_TRUE(CopyTestCache("bad_rankings2", path())); 1543 ASSERT_TRUE(CopyTestCache("bad_rankings2"));
1542 DisableFirstCleanup(); 1544 DisableFirstCleanup();
1543 SetMaxSize(20 * 1024 * 1024); 1545 SetMaxSize(20 * 1024 * 1024);
1544 InitCache(); 1546 InitCache();
1545 BackendDisable3(); 1547 BackendDisable3();
1546 } 1548 }
1547 1549
1548 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) { 1550 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess3) {
1549 ASSERT_TRUE(CopyTestCache("bad_rankings2", path())); 1551 ASSERT_TRUE(CopyTestCache("bad_rankings2"));
1550 DisableFirstCleanup(); 1552 DisableFirstCleanup();
1551 SetMaxSize(20 * 1024 * 1024); 1553 SetMaxSize(20 * 1024 * 1024);
1552 SetNewEviction(); 1554 SetNewEviction();
1553 InitCache(); 1555 InitCache();
1554 BackendDisable3(); 1556 BackendDisable3();
1555 } 1557 }
1556 1558
1557 // If we disable the cache, already open entries should work as far as possible. 1559 // If we disable the cache, already open entries should work as far as possible.
1558 void DiskCacheBackendTest::BackendDisable4() { 1560 void DiskCacheBackendTest::BackendDisable4() {
1559 disk_cache::Entry *entry1, *entry2, *entry3, *entry4; 1561 disk_cache::Entry *entry1, *entry2, *entry3, *entry4;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1597 entry1->Close(); 1599 entry1->Close();
1598 entry2->Close(); 1600 entry2->Close();
1599 entry3->Close(); 1601 entry3->Close();
1600 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. 1602 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache.
1601 FlushQueueForTest(); // This one actually allows that task to complete. 1603 FlushQueueForTest(); // This one actually allows that task to complete.
1602 1604
1603 EXPECT_EQ(0, cache_->GetEntryCount()); 1605 EXPECT_EQ(0, cache_->GetEntryCount());
1604 } 1606 }
1605 1607
1606 TEST_F(DiskCacheBackendTest, DisableSuccess4) { 1608 TEST_F(DiskCacheBackendTest, DisableSuccess4) {
1607 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); 1609 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1608 DisableFirstCleanup(); 1610 DisableFirstCleanup();
1609 SetDirectMode(); 1611 SetDirectMode();
1610 InitCache(); 1612 InitCache();
1611 BackendDisable4(); 1613 BackendDisable4();
1612 } 1614 }
1613 1615
1614 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess4) { 1616 TEST_F(DiskCacheBackendTest, NewEvictionDisableSuccess4) {
1615 ASSERT_TRUE(CopyTestCache("bad_rankings", path())); 1617 ASSERT_TRUE(CopyTestCache("bad_rankings"));
1616 DisableFirstCleanup(); 1618 DisableFirstCleanup();
1617 SetDirectMode(); 1619 SetDirectMode();
1618 SetNewEviction(); 1620 SetNewEviction();
1619 InitCache(); 1621 InitCache();
1620 BackendDisable4(); 1622 BackendDisable4();
1621 } 1623 }
1622 1624
1623 TEST_F(DiskCacheTest, Backend_UsageStats) { 1625 TEST_F(DiskCacheTest, Backend_UsageStats) {
1624 ScopedTestCache test_cache;
1625
1626 MessageLoopHelper helper; 1626 MessageLoopHelper helper;
1627 1627
1628 FilePath path = GetCacheFilePath();
1629 ASSERT_TRUE(DeleteCache(path));
1628 scoped_ptr<disk_cache::BackendImpl> cache; 1630 scoped_ptr<disk_cache::BackendImpl> cache;
1629 cache.reset(new disk_cache::BackendImpl( 1631 cache.reset(new disk_cache::BackendImpl(
1630 test_cache.path(), 1632 path, base::MessageLoopProxy::CreateForCurrentThread()));
1631 base::MessageLoopProxy::CreateForCurrentThread()));
1632 ASSERT_TRUE(NULL != cache.get()); 1633 ASSERT_TRUE(NULL != cache.get());
1633 cache->SetUnitTestMode(); 1634 cache->SetUnitTestMode();
1634 ASSERT_EQ(net::OK, cache->SyncInit()); 1635 ASSERT_EQ(net::OK, cache->SyncInit());
1635 1636
1636 // Wait for a callback that never comes... about 2 secs :). The message loop 1637 // Wait for a callback that never comes... about 2 secs :). The message loop
1637 // has to run to allow invocation of the usage timer. 1638 // has to run to allow invocation of the usage timer.
1638 helper.WaitUntilCacheIoFinished(1); 1639 helper.WaitUntilCacheIoFinished(1);
1639 } 1640 }
1640 1641
1641 void DiskCacheBackendTest::BackendDoomAll() { 1642 void DiskCacheBackendTest::BackendDoomAll() {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1707 EXPECT_EQ(net::OK, DoomAllEntries()); 1708 EXPECT_EQ(net::OK, DoomAllEntries());
1708 1709
1709 disk_cache::Entry* entry; 1710 disk_cache::Entry* entry;
1710 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry)); 1711 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry));
1711 entry->Close(); 1712 entry->Close();
1712 1713
1713 EXPECT_EQ(1, cache_->GetEntryCount()); 1714 EXPECT_EQ(1, cache_->GetEntryCount());
1714 } 1715 }
1715 1716
1716 TEST_F(DiskCacheBackendTest, DoomAll2) { 1717 TEST_F(DiskCacheBackendTest, DoomAll2) {
1717 ASSERT_TRUE(CopyTestCache("bad_rankings2", path())); 1718 ASSERT_TRUE(CopyTestCache("bad_rankings2"));
1718 DisableFirstCleanup(); 1719 DisableFirstCleanup();
1719 SetMaxSize(20 * 1024 * 1024); 1720 SetMaxSize(20 * 1024 * 1024);
1720 InitCache(); 1721 InitCache();
1721 BackendDoomAll2(); 1722 BackendDoomAll2();
1722 } 1723 }
1723 1724
1724 TEST_F(DiskCacheBackendTest, NewEvictionDoomAll2) { 1725 TEST_F(DiskCacheBackendTest, NewEvictionDoomAll2) {
1725 ASSERT_TRUE(CopyTestCache("bad_rankings2", path())); 1726 ASSERT_TRUE(CopyTestCache("bad_rankings2"));
1726 DisableFirstCleanup(); 1727 DisableFirstCleanup();
1727 SetMaxSize(20 * 1024 * 1024); 1728 SetMaxSize(20 * 1024 * 1024);
1728 SetNewEviction(); 1729 SetNewEviction();
1729 InitCache(); 1730 InitCache();
1730 BackendDoomAll2(); 1731 BackendDoomAll2();
1731 } 1732 }
1732 1733
1733 // We should be able to create the same entry on multiple simultaneous instances 1734 // We should be able to create the same entry on multiple simultaneous instances
1734 // of the cache. 1735 // of the cache.
1735 TEST_F(DiskCacheTest, MultipleInstances) { 1736 TEST_F(DiskCacheTest, MultipleInstances) {
1736 ScopedTestCache store1; 1737 ScopedTestCache store1;
1737 ScopedTestCache store2; 1738 ScopedTestCache store2("cache_test2");
1738 ScopedTestCache store3; 1739 ScopedTestCache store3("cache_test3");
1739 base::Thread cache_thread("CacheThread"); 1740 base::Thread cache_thread("CacheThread");
1740 ASSERT_TRUE(cache_thread.StartWithOptions( 1741 ASSERT_TRUE(cache_thread.StartWithOptions(
1741 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 1742 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
1742 TestCompletionCallback cb; 1743 TestCompletionCallback cb;
1743 1744
1744 const int kNumberOfCaches = 2; 1745 const int kNumberOfCaches = 2;
1745 disk_cache::Backend* cache[kNumberOfCaches]; 1746 disk_cache::Backend* cache[kNumberOfCaches];
1746 1747
1747 int rv = disk_cache::BackendImpl::CreateBackend( 1748 int rv = disk_cache::BackendImpl::CreateBackend(
1748 store1.path(), false, 0, net::DISK_CACHE, disk_cache::kNone, 1749 store1.path(), false, 0, net::DISK_CACHE, disk_cache::kNone,
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 EXPECT_EQ(kOneMB * 2, cache_impl_->GetTotalBuffersSize()); 1881 EXPECT_EQ(kOneMB * 2, cache_impl_->GetTotalBuffersSize());
1881 1882
1882 // Check the upper limit. 1883 // Check the upper limit.
1883 EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, 30 * kOneMB)); 1884 EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, 30 * kOneMB));
1884 1885
1885 for (int i = 0; i < 30; i++) 1886 for (int i = 0; i < 30; i++)
1886 cache_impl_->IsAllocAllowed(0, kOneMB); // Ignore the result. 1887 cache_impl_->IsAllocAllowed(0, kOneMB); // Ignore the result.
1887 1888
1888 EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, kOneMB)); 1889 EXPECT_FALSE(cache_impl_->IsAllocAllowed(0, kOneMB));
1889 } 1890 }
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/block_files_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698