| 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" |
| 10 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
| 11 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 12 #include "net/base/test_completion_callback.h" | 13 #include "net/base/test_completion_callback.h" |
| 13 #include "net/disk_cache/backend_impl.h" | 14 #include "net/disk_cache/backend_impl.h" |
| 14 #include "net/disk_cache/disk_cache_test_base.h" | 15 #include "net/disk_cache/disk_cache_test_base.h" |
| 15 #include "net/disk_cache/disk_cache_test_util.h" | 16 #include "net/disk_cache/disk_cache_test_util.h" |
| 16 #include "net/disk_cache/histogram_macros.h" | 17 #include "net/disk_cache/histogram_macros.h" |
| 17 #include "net/disk_cache/mapped_file.h" | 18 #include "net/disk_cache/mapped_file.h" |
| 18 #include "net/disk_cache/mem_backend_impl.h" | 19 #include "net/disk_cache/mem_backend_impl.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 ASSERT_EQ(net::OK, CreateEntry("key", &entry)); | 247 ASSERT_EQ(net::OK, CreateEntry("key", &entry)); |
| 247 ASSERT_EQ(0, entry->WriteData(0, 20000, buffer1, 0, NULL, false)); | 248 ASSERT_EQ(0, entry->WriteData(0, 20000, buffer1, 0, NULL, false)); |
| 248 entry->Close(); | 249 entry->Close(); |
| 249 | 250 |
| 250 // And verify that the first file is still there. | 251 // And verify that the first file is still there. |
| 251 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize); | 252 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize); |
| 252 ASSERT_EQ(kSize, file_util::ReadFile(filename, buffer2->data(), kSize)); | 253 ASSERT_EQ(kSize, file_util::ReadFile(filename, buffer2->data(), kSize)); |
| 253 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize)); | 254 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize)); |
| 254 } | 255 } |
| 255 | 256 |
| 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 cb; | 258 TestCompletionCallback callback; |
| 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 base::MessageLoopProxy::CreateForCurrentThread(), &cache, &cb); | 270 cache_thread.message_loop_proxy(), &cache, &callback); |
| 271 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 271 ASSERT_EQ(net::OK, callback.GetResult(rv)); |
| 272 | 272 |
| 273 disk_cache::EntryImpl* entry; | 273 disk_cache::Entry* entry; |
| 274 rv = cache->CreateEntry("some key", | 274 rv = cache->CreateEntry("some key", &entry, &callback); |
| 275 reinterpret_cast<disk_cache::Entry**>(&entry), &cb); | 275 ASSERT_EQ(net::OK, callback.GetResult(rv)); |
| 276 ASSERT_EQ(net::OK, cb.GetResult(rv)); | |
| 277 | 276 |
| 278 const int kSize = 25000; | 277 const int kSize = 25000; |
| 279 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); | 278 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); |
| 280 CacheTestFillBuffer(buffer->data(), kSize, false); | 279 CacheTestFillBuffer(buffer->data(), kSize, false); |
| 281 | 280 |
| 282 for (int i = 0; i < 10 * 1024 * 1024; i += 64 * 1024) { | 281 for (int i = 0; i < 10 * 1024 * 1024; i += 64 * 1024) { |
| 283 // We are using the current thread as the cache thread because we want to | 282 int rv = entry->WriteData(0, i, buffer, kSize, &callback, false); |
| 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); | |
| 287 if (rv == net::ERR_IO_PENDING) | 283 if (rv == net::ERR_IO_PENDING) |
| 288 break; | 284 break; |
| 289 EXPECT_EQ(kSize, rv); | 285 EXPECT_EQ(kSize, rv); |
| 290 } | 286 } |
| 291 | 287 |
| 292 // Don't call Close() to avoid going through the queue or we'll deadlock | 288 entry->Close(); |
| 293 // waiting for the operation to finish. | |
| 294 entry->Release(); | |
| 295 | 289 |
| 296 // The cache destructor will see one pending operation here. | 290 // The cache destructor will see one pending operation here. |
| 297 delete cache; | 291 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 | |
| 335 entry->Close(); | |
| 336 | |
| 337 // The cache destructor will see two pending operations here. | |
| 338 delete cache; | |
| 339 } | 292 } |
| 340 | 293 |
| 341 MessageLoop::current()->RunAllPending(); | 294 MessageLoop::current()->RunAllPending(); |
| 342 } | 295 } |
| 343 | 296 |
| 344 TEST_F(DiskCacheTest, TruncatedIndex) { | 297 TEST_F(DiskCacheTest, TruncatedIndex) { |
| 345 FilePath path = GetCacheFilePath(); | 298 FilePath path = GetCacheFilePath(); |
| 346 ASSERT_TRUE(DeleteCache(path)); | 299 ASSERT_TRUE(DeleteCache(path)); |
| 347 FilePath index = path.AppendASCII("index"); | 300 FilePath index = path.AppendASCII("index"); |
| 348 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5)); | 301 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 // By doubling the total size, we make this file cacheable. | 337 // By doubling the total size, we make this file cacheable. |
| 385 SetMaxSize(cache_size * 2); | 338 SetMaxSize(cache_size * 2); |
| 386 EXPECT_EQ(cache_size / 5, entry->WriteData(1, 0, buffer, cache_size / 5, | 339 EXPECT_EQ(cache_size / 5, entry->WriteData(1, 0, buffer, cache_size / 5, |
| 387 NULL, false)); | 340 NULL, false)); |
| 388 | 341 |
| 389 // Let's fill up the cache!. | 342 // Let's fill up the cache!. |
| 390 SetMaxSize(cache_size * 10); | 343 SetMaxSize(cache_size * 10); |
| 391 EXPECT_EQ(cache_size * 3 / 4, entry->WriteData(0, 0, buffer, | 344 EXPECT_EQ(cache_size * 3 / 4, entry->WriteData(0, 0, buffer, |
| 392 cache_size * 3 / 4, NULL, false)); | 345 cache_size * 3 / 4, NULL, false)); |
| 393 entry->Close(); | 346 entry->Close(); |
| 394 FlushQueueForTest(); | |
| 395 | 347 |
| 396 SetMaxSize(cache_size); | 348 SetMaxSize(cache_size); |
| 397 | 349 |
| 398 // The cache is 95% full. | 350 // The cache is 95% full. |
| 399 | 351 |
| 400 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); | 352 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); |
| 401 EXPECT_EQ(cache_size / 10, entry->WriteData(0, 0, buffer, cache_size / 10, | 353 EXPECT_EQ(cache_size / 10, entry->WriteData(0, 0, buffer, cache_size / 10, |
| 402 NULL, false)) << "trim the cache"; | 354 NULL, false)) << "trim the cache"; |
| 403 entry->Close(); | 355 entry->Close(); |
| 404 | 356 |
| 405 // On a slow system we may end up evicting everything not currently in use. | 357 EXPECT_NE(net::OK, OpenEntry(first, &entry)); |
| 406 ASSERT_EQ(net::OK, OpenEntry(second, &entry)); | 358 ASSERT_EQ(net::OK, OpenEntry(second, &entry)); |
| 407 EXPECT_EQ(cache_size / 10, entry->GetDataSize(0)); | 359 EXPECT_EQ(cache_size / 10, entry->GetDataSize(0)); |
| 408 entry->Close(); | 360 entry->Close(); |
| 409 | |
| 410 EXPECT_NE(net::OK, OpenEntry(first, &entry)); | |
| 411 } | 361 } |
| 412 | 362 |
| 413 TEST_F(DiskCacheBackendTest, SetSize) { | 363 TEST_F(DiskCacheBackendTest, SetSize) { |
| 414 BackendSetSize(); | 364 BackendSetSize(); |
| 415 } | 365 } |
| 416 | 366 |
| 417 TEST_F(DiskCacheBackendTest, NewEvictionSetSize) { | 367 TEST_F(DiskCacheBackendTest, NewEvictionSetSize) { |
| 418 SetNewEviction(); | 368 SetNewEviction(); |
| 419 BackendSetSize(); | 369 BackendSetSize(); |
| 420 } | 370 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 445 } | 395 } |
| 446 | 396 |
| 447 for (int i = 0; i < 100; i++) { | 397 for (int i = 0; i < 100; i++) { |
| 448 disk_cache::Entry* entry; | 398 disk_cache::Entry* entry; |
| 449 ASSERT_EQ(net::OK, OpenEntry(entries[i]->GetKey(), &entry)); | 399 ASSERT_EQ(net::OK, OpenEntry(entries[i]->GetKey(), &entry)); |
| 450 EXPECT_TRUE(entry == entries[i]); | 400 EXPECT_TRUE(entry == entries[i]); |
| 451 entry->Close(); | 401 entry->Close(); |
| 452 entries[i]->Doom(); | 402 entries[i]->Doom(); |
| 453 entries[i]->Close(); | 403 entries[i]->Close(); |
| 454 } | 404 } |
| 455 FlushQueueForTest(); | |
| 456 EXPECT_EQ(0, cache_->GetEntryCount()); | 405 EXPECT_EQ(0, cache_->GetEntryCount()); |
| 457 } | 406 } |
| 458 | 407 |
| 459 TEST_F(DiskCacheBackendTest, Load) { | 408 TEST_F(DiskCacheBackendTest, Load) { |
| 460 // Work with a tiny index table (16 entries) | 409 // Work with a tiny index table (16 entries) |
| 461 SetMask(0xf); | 410 SetMask(0xf); |
| 462 SetMaxSize(0x100000); | 411 SetMaxSize(0x100000); |
| 463 BackendLoad(); | 412 BackendLoad(); |
| 464 } | 413 } |
| 465 | 414 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 | 618 |
| 670 // Simulate a crash. | 619 // Simulate a crash. |
| 671 SimulateCrash(); | 620 SimulateCrash(); |
| 672 | 621 |
| 673 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); | 622 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); |
| 674 EXPECT_EQ(kSize, entry->WriteData(0, 0, buffer, kSize, NULL, false)); | 623 EXPECT_EQ(kSize, entry->WriteData(0, 0, buffer, kSize, NULL, false)); |
| 675 | 624 |
| 676 EXPECT_EQ(2, cache_->GetEntryCount()); | 625 EXPECT_EQ(2, cache_->GetEntryCount()); |
| 677 SetMaxSize(kSize); | 626 SetMaxSize(kSize); |
| 678 entry->Close(); // Trim the cache. | 627 entry->Close(); // Trim the cache. |
| 679 FlushQueueForTest(); | |
| 680 | 628 |
| 681 // If we evicted the entry in less than 20mS, we have one entry in the cache; | 629 // If we evicted the entry in less than 20mS, we have one entry in the cache; |
| 682 // if it took more than that, we posted a task and we'll delete the second | 630 // if it took more than that, we posted a task and we'll delete the second |
| 683 // entry too. | 631 // entry too. |
| 684 MessageLoop::current()->RunAllPending(); | 632 MessageLoop::current()->RunAllPending(); |
| 685 EXPECT_GE(1, cache_->GetEntryCount()); | 633 EXPECT_GE(1, cache_->GetEntryCount()); |
| 686 EXPECT_NE(net::OK, OpenEntry(first, &entry)); | 634 EXPECT_NE(net::OK, OpenEntry(first, &entry)); |
| 687 } | 635 } |
| 688 | 636 |
| 689 // We'll be leaking memory from this test. | 637 // We'll be leaking memory from this test. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 EXPECT_EQ(33, cache_->GetEntryCount()); | 678 EXPECT_EQ(33, cache_->GetEntryCount()); |
| 731 SetMaxSize(kSize); | 679 SetMaxSize(kSize); |
| 732 | 680 |
| 733 // For the new eviction code, all corrupt entries are on the second list so | 681 // For the new eviction code, all corrupt entries are on the second list so |
| 734 // they are not going away that easy. | 682 // they are not going away that easy. |
| 735 if (new_eviction_) { | 683 if (new_eviction_) { |
| 736 EXPECT_EQ(net::OK, DoomAllEntries()); | 684 EXPECT_EQ(net::OK, DoomAllEntries()); |
| 737 } | 685 } |
| 738 | 686 |
| 739 entry->Close(); // Trim the cache. | 687 entry->Close(); // Trim the cache. |
| 740 FlushQueueForTest(); | |
| 741 | 688 |
| 742 // We may abort the eviction before cleaning up everything. | 689 // We may abort the eviction before cleaning up everything. |
| 743 MessageLoop::current()->RunAllPending(); | 690 MessageLoop::current()->RunAllPending(); |
| 744 EXPECT_GE(30, cache_->GetEntryCount()); | 691 EXPECT_GE(30, cache_->GetEntryCount()); |
| 745 } | 692 } |
| 746 | 693 |
| 747 // We'll be leaking memory from this test. | 694 // We'll be leaking memory from this test. |
| 748 TEST_F(DiskCacheBackendTest, TrimInvalidEntry2) { | 695 TEST_F(DiskCacheBackendTest, TrimInvalidEntry2) { |
| 749 BackendTrimInvalidEntry2(); | 696 BackendTrimInvalidEntry2(); |
| 750 } | 697 } |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1305 | 1252 |
| 1306 // If the LRU is corrupt, we delete the cache. | 1253 // If the LRU is corrupt, we delete the cache. |
| 1307 void DiskCacheBackendTest::BackendInvalidRankings() { | 1254 void DiskCacheBackendTest::BackendInvalidRankings() { |
| 1308 disk_cache::Entry* entry; | 1255 disk_cache::Entry* entry; |
| 1309 void* iter = NULL; | 1256 void* iter = NULL; |
| 1310 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry)); | 1257 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry)); |
| 1311 entry->Close(); | 1258 entry->Close(); |
| 1312 EXPECT_EQ(2, cache_->GetEntryCount()); | 1259 EXPECT_EQ(2, cache_->GetEntryCount()); |
| 1313 | 1260 |
| 1314 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry)); | 1261 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry)); |
| 1315 FlushQueueForTest(); // Allow the restart to finish. | 1262 MessageLoop::current()->RunAllPending(); |
| 1316 EXPECT_EQ(0, cache_->GetEntryCount()); | 1263 EXPECT_EQ(0, cache_->GetEntryCount()); |
| 1317 } | 1264 } |
| 1318 | 1265 |
| 1319 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { | 1266 TEST_F(DiskCacheBackendTest, InvalidRankingsSuccess) { |
| 1320 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); | 1267 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); |
| 1321 DisableFirstCleanup(); | 1268 DisableFirstCleanup(); |
| 1322 SetDirectMode(); | 1269 SetDirectMode(); |
| 1323 InitCache(); | 1270 InitCache(); |
| 1324 BackendInvalidRankings(); | 1271 BackendInvalidRankings(); |
| 1325 } | 1272 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1356 void DiskCacheBackendTest::BackendDisable() { | 1303 void DiskCacheBackendTest::BackendDisable() { |
| 1357 disk_cache::Entry *entry1, *entry2; | 1304 disk_cache::Entry *entry1, *entry2; |
| 1358 void* iter = NULL; | 1305 void* iter = NULL; |
| 1359 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); | 1306 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); |
| 1360 | 1307 |
| 1361 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); | 1308 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); |
| 1362 EXPECT_EQ(2, cache_->GetEntryCount()); | 1309 EXPECT_EQ(2, cache_->GetEntryCount()); |
| 1363 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2)); | 1310 EXPECT_NE(net::OK, CreateEntry("Something new", &entry2)); |
| 1364 | 1311 |
| 1365 entry1->Close(); | 1312 entry1->Close(); |
| 1366 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. | 1313 MessageLoop::current()->RunAllPending(); |
| 1367 FlushQueueForTest(); // This one actually allows that task to complete. | |
| 1368 | 1314 |
| 1369 EXPECT_EQ(0, cache_->GetEntryCount()); | 1315 EXPECT_EQ(0, cache_->GetEntryCount()); |
| 1370 } | 1316 } |
| 1371 | 1317 |
| 1372 TEST_F(DiskCacheBackendTest, DisableSuccess) { | 1318 TEST_F(DiskCacheBackendTest, DisableSuccess) { |
| 1373 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); | 1319 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); |
| 1374 DisableFirstCleanup(); | 1320 DisableFirstCleanup(); |
| 1375 SetDirectMode(); | 1321 SetDirectMode(); |
| 1376 InitCache(); | 1322 InitCache(); |
| 1377 BackendDisable(); | 1323 BackendDisable(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1412 disk_cache::Entry* entry; | 1358 disk_cache::Entry* entry; |
| 1413 void* iter = NULL; | 1359 void* iter = NULL; |
| 1414 int count = 0; | 1360 int count = 0; |
| 1415 while (OpenNextEntry(&iter, &entry) == net::OK) { | 1361 while (OpenNextEntry(&iter, &entry) == net::OK) { |
| 1416 ASSERT_TRUE(NULL != entry); | 1362 ASSERT_TRUE(NULL != entry); |
| 1417 entry->Close(); | 1363 entry->Close(); |
| 1418 count++; | 1364 count++; |
| 1419 ASSERT_LT(count, 9); | 1365 ASSERT_LT(count, 9); |
| 1420 }; | 1366 }; |
| 1421 | 1367 |
| 1422 FlushQueueForTest(); | 1368 MessageLoop::current()->RunAllPending(); |
| 1423 EXPECT_EQ(0, cache_->GetEntryCount()); | 1369 EXPECT_EQ(0, cache_->GetEntryCount()); |
| 1424 } | 1370 } |
| 1425 | 1371 |
| 1426 TEST_F(DiskCacheBackendTest, DisableSuccess2) { | 1372 TEST_F(DiskCacheBackendTest, DisableSuccess2) { |
| 1427 ASSERT_TRUE(CopyTestCache(L"list_loop")); | 1373 ASSERT_TRUE(CopyTestCache(L"list_loop")); |
| 1428 DisableFirstCleanup(); | 1374 DisableFirstCleanup(); |
| 1429 SetDirectMode(); | 1375 SetDirectMode(); |
| 1430 InitCache(); | 1376 InitCache(); |
| 1431 BackendDisable2(); | 1377 BackendDisable2(); |
| 1432 } | 1378 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1461 | 1407 |
| 1462 // If the index size changes when we disable the cache, we should not crash. | 1408 // If the index size changes when we disable the cache, we should not crash. |
| 1463 void DiskCacheBackendTest::BackendDisable3() { | 1409 void DiskCacheBackendTest::BackendDisable3() { |
| 1464 disk_cache::Entry *entry1, *entry2; | 1410 disk_cache::Entry *entry1, *entry2; |
| 1465 void* iter = NULL; | 1411 void* iter = NULL; |
| 1466 EXPECT_EQ(2, cache_->GetEntryCount()); | 1412 EXPECT_EQ(2, cache_->GetEntryCount()); |
| 1467 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); | 1413 ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry1)); |
| 1468 entry1->Close(); | 1414 entry1->Close(); |
| 1469 | 1415 |
| 1470 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); | 1416 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry2)); |
| 1471 FlushQueueForTest(); | 1417 MessageLoop::current()->RunAllPending(); |
| 1472 | 1418 |
| 1473 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2)); | 1419 ASSERT_EQ(net::OK, CreateEntry("Something new", &entry2)); |
| 1474 entry2->Close(); | 1420 entry2->Close(); |
| 1475 | 1421 |
| 1476 EXPECT_EQ(1, cache_->GetEntryCount()); | 1422 EXPECT_EQ(1, cache_->GetEntryCount()); |
| 1477 } | 1423 } |
| 1478 | 1424 |
| 1479 TEST_F(DiskCacheBackendTest, DisableSuccess3) { | 1425 TEST_F(DiskCacheBackendTest, DisableSuccess3) { |
| 1480 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); | 1426 ASSERT_TRUE(CopyTestCache(L"bad_rankings2")); |
| 1481 DisableFirstCleanup(); | 1427 DisableFirstCleanup(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1529 EXPECT_EQ(kBufSize, entry3->WriteData(1, 0, buf, kBufSize, NULL, false)); | 1475 EXPECT_EQ(kBufSize, entry3->WriteData(1, 0, buf, kBufSize, NULL, false)); |
| 1530 | 1476 |
| 1531 std::string key = entry2->GetKey(); | 1477 std::string key = entry2->GetKey(); |
| 1532 EXPECT_EQ(sizeof(key2) - 1, key.size()); | 1478 EXPECT_EQ(sizeof(key2) - 1, key.size()); |
| 1533 key = entry3->GetKey(); | 1479 key = entry3->GetKey(); |
| 1534 EXPECT_EQ(sizeof(key3) - 1, key.size()); | 1480 EXPECT_EQ(sizeof(key3) - 1, key.size()); |
| 1535 | 1481 |
| 1536 entry1->Close(); | 1482 entry1->Close(); |
| 1537 entry2->Close(); | 1483 entry2->Close(); |
| 1538 entry3->Close(); | 1484 entry3->Close(); |
| 1539 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. | 1485 MessageLoop::current()->RunAllPending(); |
| 1540 FlushQueueForTest(); // This one actually allows that task to complete. | |
| 1541 | 1486 |
| 1542 EXPECT_EQ(0, cache_->GetEntryCount()); | 1487 EXPECT_EQ(0, cache_->GetEntryCount()); |
| 1543 } | 1488 } |
| 1544 | 1489 |
| 1545 TEST_F(DiskCacheBackendTest, DisableSuccess4) { | 1490 TEST_F(DiskCacheBackendTest, DisableSuccess4) { |
| 1546 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); | 1491 ASSERT_TRUE(CopyTestCache(L"bad_rankings")); |
| 1547 DisableFirstCleanup(); | 1492 DisableFirstCleanup(); |
| 1548 SetDirectMode(); | 1493 SetDirectMode(); |
| 1549 InitCache(); | 1494 InitCache(); |
| 1550 BackendDisable4(); | 1495 BackendDisable4(); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1752 // another. | 1697 // another. |
| 1753 TEST_F(DiskCacheBackendTest, Histograms) { | 1698 TEST_F(DiskCacheBackendTest, Histograms) { |
| 1754 SetDirectMode(); | 1699 SetDirectMode(); |
| 1755 InitCache(); | 1700 InitCache(); |
| 1756 disk_cache::BackendImpl* backend_ = cache_impl_; // Needed be the macro. | 1701 disk_cache::BackendImpl* backend_ = cache_impl_; // Needed be the macro. |
| 1757 | 1702 |
| 1758 for (int i = 1; i < 3; i++) { | 1703 for (int i = 1; i < 3; i++) { |
| 1759 CACHE_UMA(HOURS, "FillupTime", i, 28); | 1704 CACHE_UMA(HOURS, "FillupTime", i, 28); |
| 1760 } | 1705 } |
| 1761 } | 1706 } |
| OLD | NEW |