OLD | NEW |
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/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/platform_thread.h" | 8 #include "base/platform_thread.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/thread.h" | |
11 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
12 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
13 #include "net/base/test_completion_callback.h" | 12 #include "net/base/test_completion_callback.h" |
14 #include "net/disk_cache/backend_impl.h" | 13 #include "net/disk_cache/backend_impl.h" |
15 #include "net/disk_cache/disk_cache_test_base.h" | 14 #include "net/disk_cache/disk_cache_test_base.h" |
16 #include "net/disk_cache/disk_cache_test_util.h" | 15 #include "net/disk_cache/disk_cache_test_util.h" |
17 #include "net/disk_cache/histogram_macros.h" | 16 #include "net/disk_cache/histogram_macros.h" |
18 #include "net/disk_cache/mapped_file.h" | 17 #include "net/disk_cache/mapped_file.h" |
19 #include "net/disk_cache/mem_backend_impl.h" | 18 #include "net/disk_cache/mem_backend_impl.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 ASSERT_EQ(net::OK, CreateEntry("key", &entry)); | 246 ASSERT_EQ(net::OK, CreateEntry("key", &entry)); |
248 ASSERT_EQ(0, entry->WriteData(0, 20000, buffer1, 0, NULL, false)); | 247 ASSERT_EQ(0, entry->WriteData(0, 20000, buffer1, 0, NULL, false)); |
249 entry->Close(); | 248 entry->Close(); |
250 | 249 |
251 // And verify that the first file is still there. | 250 // And verify that the first file is still there. |
252 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize); | 251 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize); |
253 ASSERT_EQ(kSize, file_util::ReadFile(filename, buffer2->data(), kSize)); | 252 ASSERT_EQ(kSize, file_util::ReadFile(filename, buffer2->data(), kSize)); |
254 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize)); | 253 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize)); |
255 } | 254 } |
256 | 255 |
| 256 // Tests that we deal with file-level pending operations at destruction time. |
257 TEST_F(DiskCacheTest, ShutdownWithPendingIO) { | 257 TEST_F(DiskCacheTest, ShutdownWithPendingIO) { |
258 TestCompletionCallback callback; | 258 TestCompletionCallback cb; |
259 | 259 |
260 { | 260 { |
261 FilePath path = GetCacheFilePath(); | 261 FilePath path = GetCacheFilePath(); |
262 ASSERT_TRUE(DeleteCache(path)); | 262 ASSERT_TRUE(DeleteCache(path)); |
263 base::Thread cache_thread("CacheThread"); | 263 base::Thread cache_thread("CacheThread"); |
264 ASSERT_TRUE(cache_thread.StartWithOptions( | 264 ASSERT_TRUE(cache_thread.StartWithOptions( |
265 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 265 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
266 | 266 |
267 disk_cache::Backend* cache; | 267 disk_cache::Backend* cache; |
268 int rv = disk_cache::BackendImpl::CreateBackend( | 268 int rv = disk_cache::BackendImpl::CreateBackend( |
269 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, | 269 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, |
270 cache_thread.message_loop_proxy(), &cache, &callback); | 270 base::MessageLoopProxy::CreateForCurrentThread(), &cache, &cb); |
271 ASSERT_EQ(net::OK, callback.GetResult(rv)); | 271 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
272 | 272 |
273 disk_cache::Entry* entry; | 273 disk_cache::EntryImpl* entry; |
274 rv = cache->CreateEntry("some key", &entry, &callback); | 274 rv = cache->CreateEntry("some key", |
275 ASSERT_EQ(net::OK, callback.GetResult(rv)); | 275 reinterpret_cast<disk_cache::Entry**>(&entry), &cb); |
| 276 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
276 | 277 |
277 const int kSize = 25000; | 278 const int kSize = 25000; |
278 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); | 279 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); |
279 CacheTestFillBuffer(buffer->data(), kSize, false); | 280 CacheTestFillBuffer(buffer->data(), kSize, false); |
280 | 281 |
281 for (int i = 0; i < 10 * 1024 * 1024; i += 64 * 1024) { | 282 for (int i = 0; i < 10 * 1024 * 1024; i += 64 * 1024) { |
282 int rv = entry->WriteData(0, i, buffer, kSize, &callback, false); | 283 // We are using the current thread as the cache thread because we want to |
| 284 // be able to call directly this method to make sure that the OS (instead |
| 285 // of us switching thread) is returning IO pending. |
| 286 rv = entry->WriteDataImpl(0, i, buffer, kSize, &cb, false); |
283 if (rv == net::ERR_IO_PENDING) | 287 if (rv == net::ERR_IO_PENDING) |
284 break; | 288 break; |
285 EXPECT_EQ(kSize, rv); | 289 EXPECT_EQ(kSize, rv); |
286 } | 290 } |
287 | 291 |
| 292 // Don't call Close() to avoid going through the queue or we'll deadlock |
| 293 // waiting for the operation to finish. |
| 294 entry->Release(); |
| 295 |
| 296 // The cache destructor will see one pending operation here. |
| 297 delete cache; |
| 298 |
| 299 if (rv == net::ERR_IO_PENDING) { |
| 300 EXPECT_TRUE(cb.have_result()); |
| 301 } |
| 302 } |
| 303 |
| 304 MessageLoop::current()->RunAllPending(); |
| 305 } |
| 306 |
| 307 // Tests that we deal with background-thread pending operations. |
| 308 TEST_F(DiskCacheTest, ShutdownWithPendingIO2) { |
| 309 TestCompletionCallback cb; |
| 310 |
| 311 { |
| 312 FilePath path = GetCacheFilePath(); |
| 313 ASSERT_TRUE(DeleteCache(path)); |
| 314 base::Thread cache_thread("CacheThread"); |
| 315 ASSERT_TRUE(cache_thread.StartWithOptions( |
| 316 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
| 317 |
| 318 disk_cache::Backend* cache; |
| 319 int rv = disk_cache::BackendImpl::CreateBackend( |
| 320 path, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, |
| 321 cache_thread.message_loop_proxy(), &cache, &cb); |
| 322 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 323 |
| 324 disk_cache::Entry* entry; |
| 325 rv = cache->CreateEntry("some key", &entry, &cb); |
| 326 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 327 |
| 328 const int kSize = 25000; |
| 329 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); |
| 330 CacheTestFillBuffer(buffer->data(), kSize, false); |
| 331 |
| 332 rv = entry->WriteData(0, 0, buffer, kSize, &cb, false); |
| 333 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
| 334 |
288 entry->Close(); | 335 entry->Close(); |
289 | 336 |
290 // The cache destructor will see one pending operation here. | 337 // The cache destructor will see two pending operations here. |
291 delete cache; | 338 delete cache; |
292 } | 339 } |
293 | 340 |
294 MessageLoop::current()->RunAllPending(); | 341 MessageLoop::current()->RunAllPending(); |
295 } | 342 } |
296 | 343 |
297 TEST_F(DiskCacheTest, TruncatedIndex) { | 344 TEST_F(DiskCacheTest, TruncatedIndex) { |
298 FilePath path = GetCacheFilePath(); | 345 FilePath path = GetCacheFilePath(); |
299 ASSERT_TRUE(DeleteCache(path)); | 346 ASSERT_TRUE(DeleteCache(path)); |
300 FilePath index = path.AppendASCII("index"); | 347 FilePath index = path.AppendASCII("index"); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 // By doubling the total size, we make this file cacheable. | 384 // By doubling the total size, we make this file cacheable. |
338 SetMaxSize(cache_size * 2); | 385 SetMaxSize(cache_size * 2); |
339 EXPECT_EQ(cache_size / 5, entry->WriteData(1, 0, buffer, cache_size / 5, | 386 EXPECT_EQ(cache_size / 5, entry->WriteData(1, 0, buffer, cache_size / 5, |
340 NULL, false)); | 387 NULL, false)); |
341 | 388 |
342 // Let's fill up the cache!. | 389 // Let's fill up the cache!. |
343 SetMaxSize(cache_size * 10); | 390 SetMaxSize(cache_size * 10); |
344 EXPECT_EQ(cache_size * 3 / 4, entry->WriteData(0, 0, buffer, | 391 EXPECT_EQ(cache_size * 3 / 4, entry->WriteData(0, 0, buffer, |
345 cache_size * 3 / 4, NULL, false)); | 392 cache_size * 3 / 4, NULL, false)); |
346 entry->Close(); | 393 entry->Close(); |
| 394 FlushQueueForTest(); |
347 | 395 |
348 SetMaxSize(cache_size); | 396 SetMaxSize(cache_size); |
349 | 397 |
350 // The cache is 95% full. | 398 // The cache is 95% full. |
351 | 399 |
352 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); | 400 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); |
353 EXPECT_EQ(cache_size / 10, entry->WriteData(0, 0, buffer, cache_size / 10, | 401 EXPECT_EQ(cache_size / 10, entry->WriteData(0, 0, buffer, cache_size / 10, |
354 NULL, false)) << "trim the cache"; | 402 NULL, false)); |
| 403 |
| 404 disk_cache::Entry* entry2; |
| 405 ASSERT_EQ(net::OK, CreateEntry("an extra key", &entry2)); |
| 406 EXPECT_EQ(cache_size / 10, entry2->WriteData(0, 0, buffer, cache_size / 10, |
| 407 NULL, false)); |
| 408 entry2->Close(); // This will trigger the cache trim. |
| 409 |
| 410 EXPECT_NE(net::OK, OpenEntry(first, &entry2)); |
| 411 |
| 412 FlushQueueForTest(); // Make sure that we are done trimming the cache. |
| 413 FlushQueueForTest(); // We may have posted two tasks to evict stuff. |
| 414 |
355 entry->Close(); | 415 entry->Close(); |
356 | |
357 EXPECT_NE(net::OK, OpenEntry(first, &entry)); | |
358 ASSERT_EQ(net::OK, OpenEntry(second, &entry)); | 416 ASSERT_EQ(net::OK, OpenEntry(second, &entry)); |
359 EXPECT_EQ(cache_size / 10, entry->GetDataSize(0)); | 417 EXPECT_EQ(cache_size / 10, entry->GetDataSize(0)); |
360 entry->Close(); | 418 entry->Close(); |
361 } | 419 } |
362 | 420 |
363 TEST_F(DiskCacheBackendTest, SetSize) { | 421 TEST_F(DiskCacheBackendTest, SetSize) { |
364 BackendSetSize(); | 422 BackendSetSize(); |
365 } | 423 } |
366 | 424 |
367 TEST_F(DiskCacheBackendTest, NewEvictionSetSize) { | 425 TEST_F(DiskCacheBackendTest, NewEvictionSetSize) { |
(...skipping 27 matching lines...) Expand all Loading... |
395 } | 453 } |
396 | 454 |
397 for (int i = 0; i < 100; i++) { | 455 for (int i = 0; i < 100; i++) { |
398 disk_cache::Entry* entry; | 456 disk_cache::Entry* entry; |
399 ASSERT_EQ(net::OK, OpenEntry(entries[i]->GetKey(), &entry)); | 457 ASSERT_EQ(net::OK, OpenEntry(entries[i]->GetKey(), &entry)); |
400 EXPECT_TRUE(entry == entries[i]); | 458 EXPECT_TRUE(entry == entries[i]); |
401 entry->Close(); | 459 entry->Close(); |
402 entries[i]->Doom(); | 460 entries[i]->Doom(); |
403 entries[i]->Close(); | 461 entries[i]->Close(); |
404 } | 462 } |
| 463 FlushQueueForTest(); |
405 EXPECT_EQ(0, cache_->GetEntryCount()); | 464 EXPECT_EQ(0, cache_->GetEntryCount()); |
406 } | 465 } |
407 | 466 |
408 TEST_F(DiskCacheBackendTest, Load) { | 467 TEST_F(DiskCacheBackendTest, Load) { |
409 // Work with a tiny index table (16 entries) | 468 // Work with a tiny index table (16 entries) |
410 SetMask(0xf); | 469 SetMask(0xf); |
411 SetMaxSize(0x100000); | 470 SetMaxSize(0x100000); |
412 BackendLoad(); | 471 BackendLoad(); |
413 } | 472 } |
414 | 473 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 | 677 |
619 // Simulate a crash. | 678 // Simulate a crash. |
620 SimulateCrash(); | 679 SimulateCrash(); |
621 | 680 |
622 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); | 681 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); |
623 EXPECT_EQ(kSize, entry->WriteData(0, 0, buffer, kSize, NULL, false)); | 682 EXPECT_EQ(kSize, entry->WriteData(0, 0, buffer, kSize, NULL, false)); |
624 | 683 |
625 EXPECT_EQ(2, cache_->GetEntryCount()); | 684 EXPECT_EQ(2, cache_->GetEntryCount()); |
626 SetMaxSize(kSize); | 685 SetMaxSize(kSize); |
627 entry->Close(); // Trim the cache. | 686 entry->Close(); // Trim the cache. |
| 687 FlushQueueForTest(); |
628 | 688 |
629 // If we evicted the entry in less than 20mS, we have one entry in the cache; | 689 // If we evicted the entry in less than 20mS, we have one entry in the cache; |
630 // if it took more than that, we posted a task and we'll delete the second | 690 // if it took more than that, we posted a task and we'll delete the second |
631 // entry too. | 691 // entry too. |
632 MessageLoop::current()->RunAllPending(); | 692 MessageLoop::current()->RunAllPending(); |
633 EXPECT_GE(1, cache_->GetEntryCount()); | 693 EXPECT_GE(1, cache_->GetEntryCount()); |
634 EXPECT_NE(net::OK, OpenEntry(first, &entry)); | 694 EXPECT_NE(net::OK, OpenEntry(first, &entry)); |
635 } | 695 } |
636 | 696 |
637 // We'll be leaking memory from this test. | 697 // We'll be leaking memory from this test. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 EXPECT_EQ(33, cache_->GetEntryCount()); | 738 EXPECT_EQ(33, cache_->GetEntryCount()); |
679 SetMaxSize(kSize); | 739 SetMaxSize(kSize); |
680 | 740 |
681 // For the new eviction code, all corrupt entries are on the second list so | 741 // For the new eviction code, all corrupt entries are on the second list so |
682 // they are not going away that easy. | 742 // they are not going away that easy. |
683 if (new_eviction_) { | 743 if (new_eviction_) { |
684 EXPECT_EQ(net::OK, DoomAllEntries()); | 744 EXPECT_EQ(net::OK, DoomAllEntries()); |
685 } | 745 } |
686 | 746 |
687 entry->Close(); // Trim the cache. | 747 entry->Close(); // Trim the cache. |
| 748 FlushQueueForTest(); |
688 | 749 |
689 // We may abort the eviction before cleaning up everything. | 750 // We may abort the eviction before cleaning up everything. |
690 MessageLoop::current()->RunAllPending(); | 751 MessageLoop::current()->RunAllPending(); |
691 EXPECT_GE(30, cache_->GetEntryCount()); | 752 EXPECT_GE(30, cache_->GetEntryCount()); |
692 } | 753 } |
693 | 754 |
694 // We'll be leaking memory from this test. | 755 // We'll be leaking memory from this test. |
695 TEST_F(DiskCacheBackendTest, TrimInvalidEntry2) { | 756 TEST_F(DiskCacheBackendTest, TrimInvalidEntry2) { |
696 BackendTrimInvalidEntry2(); | 757 BackendTrimInvalidEntry2(); |
697 } | 758 } |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1252 | 1313 |
1253 // If the LRU is corrupt, we delete the cache. | 1314 // If the LRU is corrupt, we delete the cache. |
1254 void DiskCacheBackendTest::BackendInvalidRankings() { | 1315 void DiskCacheBackendTest::BackendInvalidRankings() { |
1255 disk_cache::Entry* entry; | 1316 disk_cache::Entry* entry; |
1256 void* iter = NULL; | 1317 void* iter = NULL; |
1257 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry)); | 1318 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry)); |
1258 entry->Close(); | 1319 entry->Close(); |
1259 EXPECT_EQ(2, cache_->GetEntryCount()); | 1320 EXPECT_EQ(2, cache_->GetEntryCount()); |
1260 | 1321 |
1261 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry)); | 1322 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry)); |
1262 MessageLoop::current()->RunAllPending(); | 1323 FlushQueueForTest(); // Allow the restart to finish. |
1263 EXPECT_EQ(0, cache_->GetEntryCount()); | 1324 EXPECT_EQ(0, cache_->GetEntryCount()); |
1264 } | 1325 } |
1265 | 1326 |
1266 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { | 1327 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { |
1267 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); | 1328 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); |
1268 DisableFirstCleanup(); | 1329 DisableFirstCleanup(); |
1269 SetDirectMode(); | 1330 SetDirectMode(); |
1270 InitCache(); | 1331 InitCache(); |
1271 BackendInvalidRankings(); | 1332 BackendInvalidRankings(); |
1272 } | 1333 } |
(...skipping 30 matching lines...) Expand all Loading... |
1303 void DiskCacheBackendTest::BackendDisable() { | 1364 void DiskCacheBackendTest::BackendDisable() { |
1304 disk_cache::Entry *entry1, *entry2; | 1365 disk_cache::Entry *entry1, *entry2; |
1305 void* iter = NULL; | 1366 void* iter = NULL; |
1306 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); | 1367 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); |
1307 | 1368 |
1308 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); | 1369 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); |
1309 EXPECT_EQ(2, cache_->GetEntryCount()); | 1370 EXPECT_EQ(2, cache_->GetEntryCount()); |
1310 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2)); | 1371 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2)); |
1311 | 1372 |
1312 entry1->Close(); | 1373 entry1->Close(); |
1313 MessageLoop::current()->RunAllPending(); | 1374 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. |
| 1375 FlushQueueForTest(); // This one actually allows that task to complete. |
1314 | 1376 |
1315 EXPECT_EQ(0, cache_->GetEntryCount()); | 1377 EXPECT_EQ(0, cache_->GetEntryCount()); |
1316 } | 1378 } |
1317 | 1379 |
1318 TEST_F(DiskCacheBackendTest, DisableSuccess) { | 1380 TEST_F(DiskCacheBackendTest, DisableSuccess) { |
1319 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); | 1381 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); |
1320 DisableFirstCleanup(); | 1382 DisableFirstCleanup(); |
1321 SetDirectMode(); | 1383 SetDirectMode(); |
1322 InitCache(); | 1384 InitCache(); |
1323 BackendDisable(); | 1385 BackendDisable(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1358 disk_cache::Entry* entry; | 1420 disk_cache::Entry* entry; |
1359 void* iter = NULL; | 1421 void* iter = NULL; |
1360 int count = 0; | 1422 int count = 0; |
1361 while (OpenNextEntry(&iter, &entry) == net::OK) { | 1423 while (OpenNextEntry(&iter, &entry) == net::OK) { |
1362 ASSERT_TRUE(NULL != entry); | 1424 ASSERT_TRUE(NULL != entry); |
1363 entry->Close(); | 1425 entry->Close(); |
1364 count++; | 1426 count++; |
1365 ASSERT_LT(count, 9); | 1427 ASSERT_LT(count, 9); |
1366 }; | 1428 }; |
1367 | 1429 |
1368 MessageLoop::current()->RunAllPending(); | 1430 FlushQueueForTest(); |
1369 EXPECT_EQ(0, cache_->GetEntryCount()); | 1431 EXPECT_EQ(0, cache_->GetEntryCount()); |
1370 } | 1432 } |
1371 | 1433 |
1372 TEST_F(DiskCacheBackendTest, DisableSuccess2) { | 1434 TEST_F(DiskCacheBackendTest, DisableSuccess2) { |
1373 ASSERT_TRUE(CopyTestCache(L"list_loop")); | 1435 ASSERT_TRUE(CopyTestCache(L"list_loop")); |
1374 DisableFirstCleanup(); | 1436 DisableFirstCleanup(); |
1375 SetDirectMode(); | 1437 SetDirectMode(); |
1376 InitCache(); | 1438 InitCache(); |
1377 BackendDisable2(); | 1439 BackendDisable2(); |
1378 } | 1440 } |
(...skipping 28 matching lines...) Expand all Loading... |
1407 | 1469 |
1408 // If the index size changes when we disable the cache, we should not crash. | 1470 // If the index size changes when we disable the cache, we should not crash. |
1409 void DiskCacheBackendTest::BackendDisable3() { | 1471 void DiskCacheBackendTest::BackendDisable3() { |
1410 disk_cache::Entry *entry1, *entry2; | 1472 disk_cache::Entry *entry1, *entry2; |
1411 void* iter = NULL; | 1473 void* iter = NULL; |
1412 EXPECT_EQ(2, cache_->GetEntryCount()); | 1474 EXPECT_EQ(2, cache_->GetEntryCount()); |
1413 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); | 1475 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); |
1414 entry1->Close(); | 1476 entry1->Close(); |
1415 | 1477 |
1416 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); | 1478 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); |
1417 MessageLoop::current()->RunAllPending(); | 1479 FlushQueueForTest(); |
1418 | 1480 |
1419 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2)); | 1481 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2)); |
1420 entry2->Close(); | 1482 entry2->Close(); |
1421 | 1483 |
1422 EXPECT_EQ(1, cache_->GetEntryCount()); | 1484 EXPECT_EQ(1, cache_->GetEntryCount()); |
1423 } | 1485 } |
1424 | 1486 |
1425 TEST_F(DiskCacheBackendTest, DisableSuccess3) { | 1487 TEST_F(DiskCacheBackendTest, DisableSuccess3) { |
1426 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); | 1488 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); |
1427 DisableFirstCleanup(); | 1489 DisableFirstCleanup(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1475 EXPECT_EQ(kBufSize, entry3->WriteData(1, 0, buf, kBufSize, NULL, false)); | 1537 EXPECT_EQ(kBufSize, entry3->WriteData(1, 0, buf, kBufSize, NULL, false)); |
1476 | 1538 |
1477 std::string key = entry2->GetKey(); | 1539 std::string key = entry2->GetKey(); |
1478 EXPECT_EQ(sizeof(key2) - 1, key.size()); | 1540 EXPECT_EQ(sizeof(key2) - 1, key.size()); |
1479 key = entry3->GetKey(); | 1541 key = entry3->GetKey(); |
1480 EXPECT_EQ(sizeof(key3) - 1, key.size()); | 1542 EXPECT_EQ(sizeof(key3) - 1, key.size()); |
1481 | 1543 |
1482 entry1->Close(); | 1544 entry1->Close(); |
1483 entry2->Close(); | 1545 entry2->Close(); |
1484 entry3->Close(); | 1546 entry3->Close(); |
1485 MessageLoop::current()->RunAllPending(); | 1547 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. |
| 1548 FlushQueueForTest(); // This one actually allows that task to complete. |
1486 | 1549 |
1487 EXPECT_EQ(0, cache_->GetEntryCount()); | 1550 EXPECT_EQ(0, cache_->GetEntryCount()); |
1488 } | 1551 } |
1489 | 1552 |
1490 TEST_F(DiskCacheBackendTest, DisableSuccess4) { | 1553 TEST_F(DiskCacheBackendTest, DisableSuccess4) { |
1491 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); | 1554 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); |
1492 DisableFirstCleanup(); | 1555 DisableFirstCleanup(); |
1493 SetDirectMode(); | 1556 SetDirectMode(); |
1494 InitCache(); | 1557 InitCache(); |
1495 BackendDisable4(); | 1558 BackendDisable4(); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1697 // another. | 1760 // another. |
1698 TEST_F(DiskCacheBackendTest, Histograms) { | 1761 TEST_F(DiskCacheBackendTest, Histograms) { |
1699 SetDirectMode(); | 1762 SetDirectMode(); |
1700 InitCache(); | 1763 InitCache(); |
1701 disk_cache::BackendImpl* backend_ = cache_impl_; // Needed be the macro. | 1764 disk_cache::BackendImpl* backend_ = cache_impl_; // Needed be the macro. |
1702 | 1765 |
1703 for (int i = 1; i < 3; i++) { | 1766 for (int i = 1; i < 3; i++) { |
1704 CACHE_UMA(HOURS, "FillupTime", i, 28); | 1767 CACHE_UMA(HOURS, "FillupTime", i, 28); |
1705 } | 1768 } |
1706 } | 1769 } |
OLD | NEW |