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

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

Issue 11275088: Remove implicit scoped_refptr operator T* Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « net/curvecp/test_server.cc ('k') | net/disk_cache/entry_impl.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) 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/file_util.h" 6 #include "base/file_util.h"
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 9 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
10 #include "base/threading/platform_thread.h" 10 #include "base/threading/platform_thread.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 { 204 {
205 ASSERT_TRUE(CleanupCacheDir()); 205 ASSERT_TRUE(CleanupCacheDir());
206 base::Thread cache_thread("CacheThread"); 206 base::Thread cache_thread("CacheThread");
207 ASSERT_TRUE(cache_thread.StartWithOptions( 207 ASSERT_TRUE(cache_thread.StartWithOptions(
208 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 208 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
209 209
210 // Test the private factory methods. 210 // Test the private factory methods.
211 disk_cache::Backend* cache = NULL; 211 disk_cache::Backend* cache = NULL;
212 int rv = disk_cache::BackendImpl::CreateBackend( 212 int rv = disk_cache::BackendImpl::CreateBackend(
213 cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNoRandom, 213 cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNoRandom,
214 cache_thread.message_loop_proxy(), NULL, &cache, cb.callback()); 214 cache_thread.message_loop_proxy().get(), NULL, &cache, cb.callback());
215 ASSERT_EQ(net::OK, cb.GetResult(rv)); 215 ASSERT_EQ(net::OK, cb.GetResult(rv));
216 ASSERT_TRUE(cache); 216 ASSERT_TRUE(cache);
217 delete cache; 217 delete cache;
218 218
219 cache = disk_cache::MemBackendImpl::CreateBackend(0, NULL); 219 cache = disk_cache::MemBackendImpl::CreateBackend(0, NULL);
220 ASSERT_TRUE(cache); 220 ASSERT_TRUE(cache);
221 delete cache; 221 delete cache;
222 cache = NULL; 222 cache = NULL;
223 223
224 // Now test the public API. 224 // Now test the public API.
225 rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, cache_path_, 0, false, 225 rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, cache_path_, 0, false,
226 cache_thread.message_loop_proxy(), 226 cache_thread.message_loop_proxy().get(),
227 NULL, &cache, cb.callback()); 227 NULL, &cache, cb.callback());
228 ASSERT_EQ(net::OK, cb.GetResult(rv)); 228 ASSERT_EQ(net::OK, cb.GetResult(rv));
229 ASSERT_TRUE(cache); 229 ASSERT_TRUE(cache);
230 delete cache; 230 delete cache;
231 cache = NULL; 231 cache = NULL;
232 232
233 rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE, FilePath(), 0, false, 233 rv = disk_cache::CreateCacheBackend(net::MEMORY_CACHE, FilePath(), 0, false,
234 NULL, NULL, &cache, cb.callback()); 234 NULL, NULL, &cache, cb.callback());
235 ASSERT_EQ(net::OK, cb.GetResult(rv)); 235 ASSERT_EQ(net::OK, cb.GetResult(rv));
236 ASSERT_TRUE(cache); 236 ASSERT_TRUE(cache);
(...skipping 22 matching lines...) Expand all
259 FilePath filename = cache_path_.AppendASCII("f_000001"); 259 FilePath filename = cache_path_.AppendASCII("f_000001");
260 260
261 const int kSize = 50; 261 const int kSize = 50;
262 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); 262 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize));
263 CacheTestFillBuffer(buffer1->data(), kSize, false); 263 CacheTestFillBuffer(buffer1->data(), kSize, false);
264 ASSERT_EQ(kSize, file_util::WriteFile(filename, buffer1->data(), kSize)); 264 ASSERT_EQ(kSize, file_util::WriteFile(filename, buffer1->data(), kSize));
265 265
266 // Now let's create a file with the cache. 266 // Now let's create a file with the cache.
267 disk_cache::Entry* entry; 267 disk_cache::Entry* entry;
268 ASSERT_EQ(net::OK, CreateEntry("key", &entry)); 268 ASSERT_EQ(net::OK, CreateEntry("key", &entry));
269 ASSERT_EQ(0, WriteData(entry, 0, 20000, buffer1, 0, false)); 269 ASSERT_EQ(0, WriteData(entry, 0, 20000, buffer1.get(), 0, false));
270 entry->Close(); 270 entry->Close();
271 271
272 // And verify that the first file is still there. 272 // And verify that the first file is still there.
273 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize)); 273 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize));
274 ASSERT_EQ(kSize, file_util::ReadFile(filename, buffer2->data(), kSize)); 274 ASSERT_EQ(kSize, file_util::ReadFile(filename, buffer2->data(), kSize));
275 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize)); 275 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize));
276 } 276 }
277 277
278 // Tests that we deal with file-level pending operations at destruction time. 278 // Tests that we deal with file-level pending operations at destruction time.
279 void DiskCacheBackendTest::BackendShutdownWithPendingFileIO(bool fast) { 279 void DiskCacheBackendTest::BackendShutdownWithPendingFileIO(bool fast) {
280 net::TestCompletionCallback cb; 280 net::TestCompletionCallback cb;
281 int rv; 281 int rv;
282 282
283 { 283 {
284 ASSERT_TRUE(CleanupCacheDir()); 284 ASSERT_TRUE(CleanupCacheDir());
285 base::Thread cache_thread("CacheThread"); 285 base::Thread cache_thread("CacheThread");
286 ASSERT_TRUE(cache_thread.StartWithOptions( 286 ASSERT_TRUE(cache_thread.StartWithOptions(
287 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 287 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
288 288
289 disk_cache::Backend* cache; 289 disk_cache::Backend* cache;
290 uint32 flags = disk_cache::kNoBuffering; 290 uint32 flags = disk_cache::kNoBuffering;
291 if (!fast) 291 if (!fast)
292 flags |= disk_cache::kNoRandom; 292 flags |= disk_cache::kNoRandom;
293 rv = disk_cache::BackendImpl::CreateBackend( 293 rv = disk_cache::BackendImpl::CreateBackend(
294 cache_path_, false, 0, net::DISK_CACHE, flags, 294 cache_path_, false, 0, net::DISK_CACHE, flags,
295 base::MessageLoopProxy::current(), NULL, 295 base::MessageLoopProxy::current().get(), NULL,
296 &cache, cb.callback()); 296 &cache, cb.callback());
297 ASSERT_EQ(net::OK, cb.GetResult(rv)); 297 ASSERT_EQ(net::OK, cb.GetResult(rv));
298 298
299 disk_cache::EntryImpl* entry; 299 disk_cache::EntryImpl* entry;
300 rv = cache->CreateEntry( 300 rv = cache->CreateEntry(
301 "some key", reinterpret_cast<disk_cache::Entry**>(&entry), 301 "some key", reinterpret_cast<disk_cache::Entry**>(&entry),
302 cb.callback()); 302 cb.callback());
303 ASSERT_EQ(net::OK, cb.GetResult(rv)); 303 ASSERT_EQ(net::OK, cb.GetResult(rv));
304 304
305 const int kSize = 25000; 305 const int kSize = 25000;
306 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); 306 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
307 CacheTestFillBuffer(buffer->data(), kSize, false); 307 CacheTestFillBuffer(buffer->data(), kSize, false);
308 308
309 for (int i = 0; i < 10 * 1024 * 1024; i += 64 * 1024) { 309 for (int i = 0; i < 10 * 1024 * 1024; i += 64 * 1024) {
310 // We are using the current thread as the cache thread because we want to 310 // We are using the current thread as the cache thread because we want to
311 // be able to call directly this method to make sure that the OS (instead 311 // be able to call directly this method to make sure that the OS (instead
312 // of us switching thread) is returning IO pending. 312 // of us switching thread) is returning IO pending.
313 rv = entry->WriteDataImpl(0, i, buffer, kSize, cb.callback(), false); 313 rv = entry->
314 WriteDataImpl(0, i, buffer.get(), kSize, cb.callback(), false);
314 if (rv == net::ERR_IO_PENDING) 315 if (rv == net::ERR_IO_PENDING)
315 break; 316 break;
316 EXPECT_EQ(kSize, rv); 317 EXPECT_EQ(kSize, rv);
317 } 318 }
318 319
319 // Don't call Close() to avoid going through the queue or we'll deadlock 320 // Don't call Close() to avoid going through the queue or we'll deadlock
320 // waiting for the operation to finish. 321 // waiting for the operation to finish.
321 entry->Release(); 322 entry->Release();
322 323
323 // The cache destructor will see one pending operation here. 324 // The cache destructor will see one pending operation here.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 base::Thread cache_thread("CacheThread"); 364 base::Thread cache_thread("CacheThread");
364 ASSERT_TRUE(cache_thread.StartWithOptions( 365 ASSERT_TRUE(cache_thread.StartWithOptions(
365 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 366 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
366 367
367 disk_cache::Backend* cache; 368 disk_cache::Backend* cache;
368 uint32 flags = disk_cache::kNoBuffering; 369 uint32 flags = disk_cache::kNoBuffering;
369 if (!fast) 370 if (!fast)
370 flags |= disk_cache::kNoRandom; 371 flags |= disk_cache::kNoRandom;
371 int rv = disk_cache::BackendImpl::CreateBackend( 372 int rv = disk_cache::BackendImpl::CreateBackend(
372 cache_path_, false, 0, net::DISK_CACHE, flags, 373 cache_path_, false, 0, net::DISK_CACHE, flags,
373 cache_thread.message_loop_proxy(), NULL, &cache, cb.callback()); 374 cache_thread.message_loop_proxy().get(), NULL, &cache, cb.callback());
374 ASSERT_EQ(net::OK, cb.GetResult(rv)); 375 ASSERT_EQ(net::OK, cb.GetResult(rv));
375 376
376 disk_cache::Entry* entry; 377 disk_cache::Entry* entry;
377 rv = cache->CreateEntry("some key", &entry, cb.callback()); 378 rv = cache->CreateEntry("some key", &entry, cb.callback());
378 ASSERT_EQ(net::OK, cb.GetResult(rv)); 379 ASSERT_EQ(net::OK, cb.GetResult(rv));
379 380
380 entry->Close(); 381 entry->Close();
381 382
382 // The cache destructor will see one pending operation here. 383 // The cache destructor will see one pending operation here.
383 delete cache; 384 delete cache;
(...skipping 22 matching lines...) Expand all
406 ASSERT_TRUE(CleanupCacheDir()); 407 ASSERT_TRUE(CleanupCacheDir());
407 base::Thread cache_thread("CacheThread"); 408 base::Thread cache_thread("CacheThread");
408 ASSERT_TRUE(cache_thread.StartWithOptions( 409 ASSERT_TRUE(cache_thread.StartWithOptions(
409 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 410 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
410 411
411 disk_cache::Backend* cache; 412 disk_cache::Backend* cache;
412 disk_cache::BackendFlags flags = 413 disk_cache::BackendFlags flags =
413 fast ? disk_cache::kNone : disk_cache::kNoRandom; 414 fast ? disk_cache::kNone : disk_cache::kNoRandom;
414 int rv = disk_cache::BackendImpl::CreateBackend( 415 int rv = disk_cache::BackendImpl::CreateBackend(
415 cache_path_, false, 0, net::DISK_CACHE, flags, 416 cache_path_, false, 0, net::DISK_CACHE, flags,
416 cache_thread.message_loop_proxy(), NULL, &cache, cb.callback()); 417 cache_thread.message_loop_proxy().get(), NULL, &cache, cb.callback());
417 ASSERT_EQ(net::OK, cb.GetResult(rv)); 418 ASSERT_EQ(net::OK, cb.GetResult(rv));
418 419
419 disk_cache::Entry* entry; 420 disk_cache::Entry* entry;
420 rv = cache->CreateEntry("some key", &entry, cb.callback()); 421 rv = cache->CreateEntry("some key", &entry, cb.callback());
421 ASSERT_EQ(net::ERR_IO_PENDING, rv); 422 ASSERT_EQ(net::ERR_IO_PENDING, rv);
422 423
423 delete cache; 424 delete cache;
424 EXPECT_FALSE(cb.have_result()); 425 EXPECT_FALSE(cb.have_result());
425 } 426 }
426 427
(...skipping 18 matching lines...) Expand all
445 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5)); 446 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5));
446 447
447 base::Thread cache_thread("CacheThread"); 448 base::Thread cache_thread("CacheThread");
448 ASSERT_TRUE(cache_thread.StartWithOptions( 449 ASSERT_TRUE(cache_thread.StartWithOptions(
449 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 450 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
450 net::TestCompletionCallback cb; 451 net::TestCompletionCallback cb;
451 452
452 disk_cache::Backend* backend = NULL; 453 disk_cache::Backend* backend = NULL;
453 int rv = disk_cache::BackendImpl::CreateBackend( 454 int rv = disk_cache::BackendImpl::CreateBackend(
454 cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNone, 455 cache_path_, false, 0, net::DISK_CACHE, disk_cache::kNone,
455 cache_thread.message_loop_proxy(), NULL, &backend, cb.callback()); 456 cache_thread.message_loop_proxy().get(), NULL, &backend, cb.callback());
456 ASSERT_NE(net::OK, cb.GetResult(rv)); 457 ASSERT_NE(net::OK, cb.GetResult(rv));
457 458
458 ASSERT_TRUE(backend == NULL); 459 ASSERT_TRUE(backend == NULL);
459 delete backend; 460 delete backend;
460 } 461 }
461 462
462 void DiskCacheBackendTest::BackendSetSize() { 463 void DiskCacheBackendTest::BackendSetSize() {
463 SetDirectMode(); 464 SetDirectMode();
464 const int cache_size = 0x10000; // 64 kB 465 const int cache_size = 0x10000; // 64 kB
465 SetMaxSize(cache_size); 466 SetMaxSize(cache_size);
466 InitCache(); 467 InitCache();
467 468
468 std::string first("some key"); 469 std::string first("some key");
469 std::string second("something else"); 470 std::string second("something else");
470 disk_cache::Entry* entry; 471 disk_cache::Entry* entry;
471 ASSERT_EQ(net::OK, CreateEntry(first, &entry)); 472 ASSERT_EQ(net::OK, CreateEntry(first, &entry));
472 473
473 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(cache_size)); 474 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(cache_size));
474 memset(buffer->data(), 0, cache_size); 475 memset(buffer->data(), 0, cache_size);
475 EXPECT_EQ(cache_size / 10, WriteData(entry, 0, 0, buffer, cache_size / 10, 476 EXPECT_EQ(
476 false)) << "normal file"; 477 cache_size / 10, WriteData(entry, 0, 0, buffer.get(), cache_size / 10,
478 false)) << "normal file";
477 479
478 EXPECT_EQ(net::ERR_FAILED, WriteData(entry, 1, 0, buffer, cache_size / 5, 480 EXPECT_EQ(
479 false)) << "file size above the limit"; 481 net::ERR_FAILED, WriteData(entry, 1, 0, buffer.get(), cache_size / 5,
482 false)) << "file size above the limit";
480 483
481 // By doubling the total size, we make this file cacheable. 484 // By doubling the total size, we make this file cacheable.
482 SetMaxSize(cache_size * 2); 485 SetMaxSize(cache_size * 2);
483 EXPECT_EQ(cache_size / 5, WriteData(entry, 1, 0, buffer, cache_size / 5, 486 EXPECT_EQ(cache_size / 5, WriteData(entry, 1, 0, buffer.get(), cache_size / 5,
484 false)); 487 false));
485 488
486 // Let's fill up the cache!. 489 // Let's fill up the cache!.
487 SetMaxSize(cache_size * 10); 490 SetMaxSize(cache_size * 10);
488 EXPECT_EQ(cache_size * 3 / 4, WriteData(entry, 0, 0, buffer, 491 EXPECT_EQ(cache_size * 3 / 4, WriteData(entry, 0, 0, buffer.get(),
489 cache_size * 3 / 4, false)); 492 cache_size * 3 / 4, false));
490 entry->Close(); 493 entry->Close();
491 FlushQueueForTest(); 494 FlushQueueForTest();
492 495
493 SetMaxSize(cache_size); 496 SetMaxSize(cache_size);
494 497
495 // The cache is 95% full. 498 // The cache is 95% full.
496 499
497 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); 500 ASSERT_EQ(net::OK, CreateEntry(second, &entry));
498 EXPECT_EQ(cache_size / 10, WriteData(entry, 0, 0, buffer, cache_size / 10, 501 EXPECT_EQ(
499 false)); 502 cache_size / 10, WriteData(entry, 0, 0, buffer.get(), cache_size / 10,
503 false));
500 504
501 disk_cache::Entry* entry2; 505 disk_cache::Entry* entry2;
502 ASSERT_EQ(net::OK, CreateEntry("an extra key", &entry2)); 506 ASSERT_EQ(net::OK, CreateEntry("an extra key", &entry2));
503 EXPECT_EQ(cache_size / 10, WriteData(entry2, 0, 0, buffer, cache_size / 10, 507 EXPECT_EQ(
504 false)); 508 cache_size / 10, WriteData(entry2, 0, 0, buffer.get(), cache_size / 10,
509 false));
505 entry2->Close(); // This will trigger the cache trim. 510 entry2->Close(); // This will trigger the cache trim.
506 511
507 EXPECT_NE(net::OK, OpenEntry(first, &entry2)); 512 EXPECT_NE(net::OK, OpenEntry(first, &entry2));
508 513
509 FlushQueueForTest(); // Make sure that we are done trimming the cache. 514 FlushQueueForTest(); // Make sure that we are done trimming the cache.
510 FlushQueueForTest(); // We may have posted two tasks to evict stuff. 515 FlushQueueForTest(); // We may have posted two tasks to evict stuff.
511 516
512 entry->Close(); 517 entry->Close();
513 ASSERT_EQ(net::OK, OpenEntry(second, &entry)); 518 ASSERT_EQ(net::OK, OpenEntry(second, &entry));
514 EXPECT_EQ(cache_size / 10, entry->GetDataSize(0)); 519 EXPECT_EQ(cache_size / 10, entry->GetDataSize(0));
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 InitCache(); 660 InitCache();
656 661
657 std::string key("Some key"); 662 std::string key("Some key");
658 disk_cache::Entry* entry; 663 disk_cache::Entry* entry;
659 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 664 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
660 665
661 const int kSize = 50; 666 const int kSize = 50;
662 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); 667 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize));
663 memset(buffer1->data(), 0, kSize); 668 memset(buffer1->data(), 0, kSize);
664 base::strlcpy(buffer1->data(), "And the data to save", kSize); 669 base::strlcpy(buffer1->data(), "And the data to save", kSize);
665 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer1, kSize, false)); 670 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer1.get(), kSize, false));
666 entry->Close(); 671 entry->Close();
667 SimulateCrash(); 672 SimulateCrash();
668 673
669 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); 674 ASSERT_EQ(net::OK, OpenEntry(key, &entry));
670 675
671 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize)); 676 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize));
672 memset(buffer2->data(), 0, kSize); 677 memset(buffer2->data(), 0, kSize);
673 EXPECT_EQ(kSize, ReadData(entry, 0, 0, buffer2, kSize)); 678 EXPECT_EQ(kSize, ReadData(entry, 0, 0, buffer2.get(), kSize));
674 entry->Close(); 679 entry->Close();
675 EXPECT_STREQ(buffer1->data(), buffer2->data()); 680 EXPECT_STREQ(buffer1->data(), buffer2->data());
676 } 681 }
677 682
678 TEST_F(DiskCacheBackendTest, ValidEntry) { 683 TEST_F(DiskCacheBackendTest, ValidEntry) {
679 BackendValidEntry(); 684 BackendValidEntry();
680 } 685 }
681 686
682 TEST_F(DiskCacheBackendTest, NewEvictionValidEntry) { 687 TEST_F(DiskCacheBackendTest, NewEvictionValidEntry) {
683 SetNewEviction(); 688 SetNewEviction();
684 BackendValidEntry(); 689 BackendValidEntry();
685 } 690 }
686 691
687 // The same logic of the previous test (ValidEntry), but this time force the 692 // The same logic of the previous test (ValidEntry), but this time force the
688 // entry to be invalid, simulating a crash in the middle. 693 // entry to be invalid, simulating a crash in the middle.
689 // We'll be leaking memory from this test. 694 // We'll be leaking memory from this test.
690 void DiskCacheBackendTest::BackendInvalidEntry() { 695 void DiskCacheBackendTest::BackendInvalidEntry() {
691 // Use the implementation directly... we need to simulate a crash. 696 // Use the implementation directly... we need to simulate a crash.
692 SetDirectMode(); 697 SetDirectMode();
693 InitCache(); 698 InitCache();
694 699
695 std::string key("Some key"); 700 std::string key("Some key");
696 disk_cache::Entry* entry; 701 disk_cache::Entry* entry;
697 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 702 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
698 703
699 const int kSize = 50; 704 const int kSize = 50;
700 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); 705 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
701 memset(buffer->data(), 0, kSize); 706 memset(buffer->data(), 0, kSize);
702 base::strlcpy(buffer->data(), "And the data to save", kSize); 707 base::strlcpy(buffer->data(), "And the data to save", kSize);
703 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer, kSize, false)); 708 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer.get(), kSize, false));
704 SimulateCrash(); 709 SimulateCrash();
705 710
706 EXPECT_NE(net::OK, OpenEntry(key, &entry)); 711 EXPECT_NE(net::OK, OpenEntry(key, &entry));
707 EXPECT_EQ(0, cache_->GetEntryCount()); 712 EXPECT_EQ(0, cache_->GetEntryCount());
708 } 713 }
709 714
710 // This and the other intentionally leaky tests below are excluded from 715 // This and the other intentionally leaky tests below are excluded from
711 // valgrind runs by naming them in the files 716 // valgrind runs by naming them in the files
712 // net/data/valgrind/net_unittests.gtest.txt 717 // net/data/valgrind/net_unittests.gtest.txt
713 // The scripts tools/valgrind/chrome_tests.sh 718 // The scripts tools/valgrind/chrome_tests.sh
(...skipping 22 matching lines...) Expand all
736 InitCache(); 741 InitCache();
737 742
738 std::string key("Some key"); 743 std::string key("Some key");
739 disk_cache::Entry* entry; 744 disk_cache::Entry* entry;
740 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 745 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
741 746
742 const int kSize = 50; 747 const int kSize = 50;
743 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); 748 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
744 memset(buffer->data(), 0, kSize); 749 memset(buffer->data(), 0, kSize);
745 base::strlcpy(buffer->data(), "And the data to save", kSize); 750 base::strlcpy(buffer->data(), "And the data to save", kSize);
746 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer, kSize, false)); 751 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer.get(), kSize, false));
747 entry->Close(); 752 entry->Close();
748 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); 753 ASSERT_EQ(net::OK, OpenEntry(key, &entry));
749 EXPECT_EQ(kSize, ReadData(entry, 0, 0, buffer, kSize)); 754 EXPECT_EQ(kSize, ReadData(entry, 0, 0, buffer.get(), kSize));
750 755
751 SimulateCrash(); 756 SimulateCrash();
752 757
753 if (type_ == net::APP_CACHE) { 758 if (type_ == net::APP_CACHE) {
754 // Reading an entry and crashing should not make it dirty. 759 // Reading an entry and crashing should not make it dirty.
755 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); 760 ASSERT_EQ(net::OK, OpenEntry(key, &entry));
756 EXPECT_EQ(1, cache_->GetEntryCount()); 761 EXPECT_EQ(1, cache_->GetEntryCount());
757 entry->Close(); 762 entry->Close();
758 } else { 763 } else {
759 EXPECT_NE(net::OK, OpenEntry(key, &entry)); 764 EXPECT_NE(net::OK, OpenEntry(key, &entry));
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 SetMaxSize(kSize * 10); 858 SetMaxSize(kSize * 10);
854 InitCache(); 859 InitCache();
855 860
856 std::string first("some key"); 861 std::string first("some key");
857 std::string second("something else"); 862 std::string second("something else");
858 disk_cache::Entry* entry; 863 disk_cache::Entry* entry;
859 ASSERT_EQ(net::OK, CreateEntry(first, &entry)); 864 ASSERT_EQ(net::OK, CreateEntry(first, &entry));
860 865
861 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); 866 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
862 memset(buffer->data(), 0, kSize); 867 memset(buffer->data(), 0, kSize);
863 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer, kSize, false)); 868 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer.get(), kSize, false));
864 869
865 // Simulate a crash. 870 // Simulate a crash.
866 SimulateCrash(); 871 SimulateCrash();
867 872
868 ASSERT_EQ(net::OK, CreateEntry(second, &entry)); 873 ASSERT_EQ(net::OK, CreateEntry(second, &entry));
869 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer, kSize, false)); 874 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer.get(), kSize, false));
870 875
871 EXPECT_EQ(2, cache_->GetEntryCount()); 876 EXPECT_EQ(2, cache_->GetEntryCount());
872 SetMaxSize(kSize); 877 SetMaxSize(kSize);
873 entry->Close(); // Trim the cache. 878 entry->Close(); // Trim the cache.
874 FlushQueueForTest(); 879 FlushQueueForTest();
875 880
876 // If we evicted the entry in less than 20mS, we have one entry in the cache; 881 // If we evicted the entry in less than 20mS, we have one entry in the cache;
877 // if it took more than that, we posted a task and we'll delete the second 882 // if it took more than that, we posted a task and we'll delete the second
878 // entry too. 883 // entry too.
879 MessageLoop::current()->RunAllPending(); 884 MessageLoop::current()->RunAllPending();
(...skipping 30 matching lines...) Expand all
910 InitCache(); 915 InitCache();
911 916
912 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); 917 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
913 memset(buffer->data(), 0, kSize); 918 memset(buffer->data(), 0, kSize);
914 disk_cache::Entry* entry; 919 disk_cache::Entry* entry;
915 920
916 // Writing 32 entries to this cache chains most of them. 921 // Writing 32 entries to this cache chains most of them.
917 for (int i = 0; i < 32; i++) { 922 for (int i = 0; i < 32; i++) {
918 std::string key(base::StringPrintf("some key %d", i)); 923 std::string key(base::StringPrintf("some key %d", i));
919 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 924 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
920 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer, kSize, false)); 925 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer.get(), kSize, false));
921 entry->Close(); 926 entry->Close();
922 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); 927 ASSERT_EQ(net::OK, OpenEntry(key, &entry));
923 // Note that we are not closing the entries. 928 // Note that we are not closing the entries.
924 } 929 }
925 930
926 // Simulate a crash. 931 // Simulate a crash.
927 SimulateCrash(); 932 SimulateCrash();
928 933
929 ASSERT_EQ(net::OK, CreateEntry("Something else", &entry)); 934 ASSERT_EQ(net::OK, CreateEntry("Something else", &entry));
930 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer, kSize, false)); 935 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer.get(), kSize, false));
931 936
932 FlushQueueForTest(); 937 FlushQueueForTest();
933 EXPECT_EQ(33, cache_->GetEntryCount()); 938 EXPECT_EQ(33, cache_->GetEntryCount());
934 SetMaxSize(kSize); 939 SetMaxSize(kSize);
935 940
936 // For the new eviction code, all corrupt entries are on the second list so 941 // For the new eviction code, all corrupt entries are on the second list so
937 // they are not going away that easy. 942 // they are not going away that easy.
938 if (new_eviction_) { 943 if (new_eviction_) {
939 EXPECT_EQ(net::OK, DoomAllEntries()); 944 EXPECT_EQ(net::OK, DoomAllEntries());
940 } 945 }
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 InitCache(); 1109 InitCache();
1105 1110
1106 std::string key("Some key"); 1111 std::string key("Some key");
1107 disk_cache::Entry *entry, *entry1, *entry2; 1112 disk_cache::Entry *entry, *entry1, *entry2;
1108 ASSERT_EQ(net::OK, CreateEntry(key, &entry1)); 1113 ASSERT_EQ(net::OK, CreateEntry(key, &entry1));
1109 1114
1110 const int kSize = 50; 1115 const int kSize = 50;
1111 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); 1116 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize));
1112 memset(buffer1->data(), 0, kSize); 1117 memset(buffer1->data(), 0, kSize);
1113 base::strlcpy(buffer1->data(), "And the data to save", kSize); 1118 base::strlcpy(buffer1->data(), "And the data to save", kSize);
1114 EXPECT_EQ(kSize, WriteData(entry1, 0, 0, buffer1, kSize, false)); 1119 EXPECT_EQ(kSize, WriteData(entry1, 0, 0, buffer1.get(), kSize, false));
1115 entry1->Close(); 1120 entry1->Close();
1116 ASSERT_EQ(net::OK, OpenEntry(key, &entry1)); 1121 ASSERT_EQ(net::OK, OpenEntry(key, &entry1));
1117 EXPECT_EQ(kSize, ReadData(entry1, 0, 0, buffer1, kSize)); 1122 EXPECT_EQ(kSize, ReadData(entry1, 0, 0, buffer1.get(), kSize));
1118 1123
1119 std::string key2("Another key"); 1124 std::string key2("Another key");
1120 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2)); 1125 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2));
1121 entry2->Close(); 1126 entry2->Close();
1122 ASSERT_EQ(2, cache_->GetEntryCount()); 1127 ASSERT_EQ(2, cache_->GetEntryCount());
1123 1128
1124 SimulateCrash(); 1129 SimulateCrash();
1125 1130
1126 void* iter = NULL; 1131 void* iter = NULL;
1127 int count = 0; 1132 int count = 0;
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 TEST_F(DiskCacheTest, DeleteOld) { 1468 TEST_F(DiskCacheTest, DeleteOld) {
1464 ASSERT_TRUE(CopyTestCache("wrong_version")); 1469 ASSERT_TRUE(CopyTestCache("wrong_version"));
1465 base::Thread cache_thread("CacheThread"); 1470 base::Thread cache_thread("CacheThread");
1466 ASSERT_TRUE(cache_thread.StartWithOptions( 1471 ASSERT_TRUE(cache_thread.StartWithOptions(
1467 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 1472 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
1468 net::TestCompletionCallback cb; 1473 net::TestCompletionCallback cb;
1469 1474
1470 disk_cache::Backend* cache; 1475 disk_cache::Backend* cache;
1471 int rv = disk_cache::BackendImpl::CreateBackend( 1476 int rv = disk_cache::BackendImpl::CreateBackend(
1472 cache_path_, true, 0, net::DISK_CACHE, disk_cache::kNoRandom, 1477 cache_path_, true, 0, net::DISK_CACHE, disk_cache::kNoRandom,
1473 cache_thread.message_loop_proxy(), NULL, &cache, cb.callback()); 1478 cache_thread.message_loop_proxy().get(), NULL, &cache,
1479 cb.callback());
1474 ASSERT_EQ(net::OK, cb.GetResult(rv)); 1480 ASSERT_EQ(net::OK, cb.GetResult(rv));
1475 1481
1476 MessageLoopHelper helper; 1482 MessageLoopHelper helper;
1477 1483
1478 ASSERT_TRUE(NULL != cache); 1484 ASSERT_TRUE(NULL != cache);
1479 ASSERT_EQ(0, cache->GetEntryCount()); 1485 ASSERT_EQ(0, cache->GetEntryCount());
1480 1486
1481 delete cache; 1487 delete cache;
1482 } 1488 }
1483 1489
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
2188 CacheTestFillBuffer(key2, sizeof(key2), true); 2194 CacheTestFillBuffer(key2, sizeof(key2), true);
2189 CacheTestFillBuffer(key3, sizeof(key3), true); 2195 CacheTestFillBuffer(key3, sizeof(key3), true);
2190 key2[sizeof(key2) - 1] = '\0'; 2196 key2[sizeof(key2) - 1] = '\0';
2191 key3[sizeof(key3) - 1] = '\0'; 2197 key3[sizeof(key3) - 1] = '\0';
2192 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2)); 2198 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2));
2193 ASSERT_EQ(net::OK, CreateEntry(key3, &entry3)); 2199 ASSERT_EQ(net::OK, CreateEntry(key3, &entry3));
2194 2200
2195 const int kBufSize = 20000; 2201 const int kBufSize = 20000;
2196 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kBufSize)); 2202 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kBufSize));
2197 memset(buf->data(), 0, kBufSize); 2203 memset(buf->data(), 0, kBufSize);
2198 EXPECT_EQ(100, WriteData(entry2, 0, 0, buf, 100, false)); 2204 EXPECT_EQ(100, WriteData(entry2, 0, 0, buf.get(), 100, false));
2199 EXPECT_EQ(kBufSize, WriteData(entry3, 0, 0, buf, kBufSize, false)); 2205 EXPECT_EQ(kBufSize, WriteData(entry3, 0, 0, buf.get(), kBufSize, false));
2200 2206
2201 // This line should disable the cache but not delete it. 2207 // This line should disable the cache but not delete it.
2202 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry4)); 2208 EXPECT_NE(net::OK, OpenNextEntry(&iter, &entry4));
2203 EXPECT_EQ(0, cache_->GetEntryCount()); 2209 EXPECT_EQ(0, cache_->GetEntryCount());
2204 2210
2205 EXPECT_NE(net::OK, CreateEntry("cache is disabled", &entry4)); 2211 EXPECT_NE(net::OK, CreateEntry("cache is disabled", &entry4));
2206 2212
2207 EXPECT_EQ(100, ReadData(entry2, 0, 0, buf, 100)); 2213 EXPECT_EQ(100, ReadData(entry2, 0, 0, buf.get(), 100));
2208 EXPECT_EQ(100, WriteData(entry2, 0, 0, buf, 100, false)); 2214 EXPECT_EQ(100, WriteData(entry2, 0, 0, buf.get(), 100, false));
2209 EXPECT_EQ(100, WriteData(entry2, 1, 0, buf, 100, false)); 2215 EXPECT_EQ(100, WriteData(entry2, 1, 0, buf.get(), 100, false));
2210 2216
2211 EXPECT_EQ(kBufSize, ReadData(entry3, 0, 0, buf, kBufSize)); 2217 EXPECT_EQ(kBufSize, ReadData(entry3, 0, 0, buf.get(), kBufSize));
2212 EXPECT_EQ(kBufSize, WriteData(entry3, 0, 0, buf, kBufSize, false)); 2218 EXPECT_EQ(kBufSize, WriteData(entry3, 0, 0, buf.get(), kBufSize, false));
2213 EXPECT_EQ(kBufSize, WriteData(entry3, 1, 0, buf, kBufSize, false)); 2219 EXPECT_EQ(kBufSize, WriteData(entry3, 1, 0, buf.get(), kBufSize, false));
2214 2220
2215 std::string key = entry2->GetKey(); 2221 std::string key = entry2->GetKey();
2216 EXPECT_EQ(sizeof(key2) - 1, key.size()); 2222 EXPECT_EQ(sizeof(key2) - 1, key.size());
2217 key = entry3->GetKey(); 2223 key = entry3->GetKey();
2218 EXPECT_EQ(sizeof(key3) - 1, key.size()); 2224 EXPECT_EQ(sizeof(key3) - 1, key.size());
2219 2225
2220 entry1->Close(); 2226 entry1->Close();
2221 entry2->Close(); 2227 entry2->Close();
2222 entry3->Close(); 2228 entry3->Close();
2223 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache. 2229 FlushQueueForTest(); // Flushing the Close posts a task to restart the cache.
(...skipping 18 matching lines...) Expand all
2242 InitCache(); 2248 InitCache();
2243 BackendDisable4(); 2249 BackendDisable4();
2244 } 2250 }
2245 2251
2246 TEST_F(DiskCacheTest, Backend_UsageStats) { 2252 TEST_F(DiskCacheTest, Backend_UsageStats) {
2247 MessageLoopHelper helper; 2253 MessageLoopHelper helper;
2248 2254
2249 ASSERT_TRUE(CleanupCacheDir()); 2255 ASSERT_TRUE(CleanupCacheDir());
2250 scoped_ptr<disk_cache::BackendImpl> cache; 2256 scoped_ptr<disk_cache::BackendImpl> cache;
2251 cache.reset(new disk_cache::BackendImpl( 2257 cache.reset(new disk_cache::BackendImpl(
2252 cache_path_, base::MessageLoopProxy::current(), 2258 cache_path_, base::MessageLoopProxy::current().get(),
2253 NULL)); 2259 NULL));
2254 ASSERT_TRUE(NULL != cache.get()); 2260 ASSERT_TRUE(NULL != cache.get());
2255 cache->SetUnitTestMode(); 2261 cache->SetUnitTestMode();
2256 ASSERT_EQ(net::OK, cache->SyncInit()); 2262 ASSERT_EQ(net::OK, cache->SyncInit());
2257 2263
2258 // Wait for a callback that never comes... about 2 secs :). The message loop 2264 // Wait for a callback that never comes... about 2 secs :). The message loop
2259 // has to run to allow invocation of the usage timer. 2265 // has to run to allow invocation of the usage timer.
2260 helper.WaitUntilCacheIoFinished(1); 2266 helper.WaitUntilCacheIoFinished(1);
2261 } 2267 }
2262 2268
2263 void DiskCacheBackendTest::BackendDoomAll() { 2269 void DiskCacheBackendTest::BackendDoomAll() {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
2363 base::Thread cache_thread("CacheThread"); 2369 base::Thread cache_thread("CacheThread");
2364 ASSERT_TRUE(cache_thread.StartWithOptions( 2370 ASSERT_TRUE(cache_thread.StartWithOptions(
2365 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 2371 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
2366 net::TestCompletionCallback cb; 2372 net::TestCompletionCallback cb;
2367 2373
2368 const int kNumberOfCaches = 2; 2374 const int kNumberOfCaches = 2;
2369 disk_cache::Backend* cache[kNumberOfCaches]; 2375 disk_cache::Backend* cache[kNumberOfCaches];
2370 2376
2371 int rv = disk_cache::BackendImpl::CreateBackend( 2377 int rv = disk_cache::BackendImpl::CreateBackend(
2372 store1.path(), false, 0, net::DISK_CACHE, disk_cache::kNone, 2378 store1.path(), false, 0, net::DISK_CACHE, disk_cache::kNone,
2373 cache_thread.message_loop_proxy(), NULL, &cache[0], cb.callback()); 2379 cache_thread.message_loop_proxy().get(), NULL, &cache[0], cb.callback());
2374 ASSERT_EQ(net::OK, cb.GetResult(rv)); 2380 ASSERT_EQ(net::OK, cb.GetResult(rv));
2375 rv = disk_cache::BackendImpl::CreateBackend( 2381 rv = disk_cache::BackendImpl::CreateBackend(
2376 store2.path(), false, 0, net::MEDIA_CACHE, disk_cache::kNone, 2382 store2.path(), false, 0, net::MEDIA_CACHE, disk_cache::kNone,
2377 cache_thread.message_loop_proxy(), NULL, &cache[1], cb.callback()); 2383 cache_thread.message_loop_proxy().get(), NULL, &cache[1], cb.callback());
2378 ASSERT_EQ(net::OK, cb.GetResult(rv)); 2384 ASSERT_EQ(net::OK, cb.GetResult(rv));
2379 2385
2380 ASSERT_TRUE(cache[0] != NULL && cache[1] != NULL); 2386 ASSERT_TRUE(cache[0] != NULL && cache[1] != NULL);
2381 2387
2382 std::string key("the first key"); 2388 std::string key("the first key");
2383 disk_cache::Entry* entry; 2389 disk_cache::Entry* entry;
2384 for (int i = 0; i < kNumberOfCaches; i++) { 2390 for (int i = 0; i < kNumberOfCaches; i++) {
2385 rv = cache[i]->CreateEntry(key, &entry, cb.callback()); 2391 rv = cache[i]->CreateEntry(key, &entry, cb.callback());
2386 ASSERT_EQ(net::OK, cb.GetResult(rv)); 2392 ASSERT_EQ(net::OK, cb.GetResult(rv));
2387 entry->Close(); 2393 entry->Close();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2460 disk_cache::Entry* entry; 2466 disk_cache::Entry* entry;
2461 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); 2467 ASSERT_EQ(net::OK, CreateEntry(key, &entry));
2462 2468
2463 const int kSize = 200; 2469 const int kSize = 200;
2464 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); 2470 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize));
2465 CacheTestFillBuffer(buffer->data(), kSize, true); 2471 CacheTestFillBuffer(buffer->data(), kSize, true);
2466 2472
2467 for (int i = 0; i < 10; i++) { 2473 for (int i = 0; i < 10; i++) {
2468 SCOPED_TRACE(i); 2474 SCOPED_TRACE(i);
2469 // Allocate 2MB for this entry. 2475 // Allocate 2MB for this entry.
2470 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer, kSize, true)); 2476 EXPECT_EQ(kSize, WriteData(entry, 0, 0, buffer.get(), kSize, true));
2471 EXPECT_EQ(kSize, WriteData(entry, 1, 0, buffer, kSize, true)); 2477 EXPECT_EQ(kSize, WriteData(entry, 1, 0, buffer.get(), kSize, true));
2472 EXPECT_EQ(kSize, WriteData(entry, 0, 1024 * 1024, buffer, kSize, false)); 2478 EXPECT_EQ(
2473 EXPECT_EQ(kSize, WriteData(entry, 1, 1024 * 1024, buffer, kSize, false)); 2479 kSize, WriteData(entry, 0, 1024 * 1024, buffer.get(), kSize, false));
2480 EXPECT_EQ(
2481 kSize, WriteData(entry, 1, 1024 * 1024, buffer.get(), kSize, false));
2474 2482
2475 // Delete one of the buffers and truncate the other. 2483 // Delete one of the buffers and truncate the other.
2476 EXPECT_EQ(0, WriteData(entry, 0, 0, buffer, 0, true)); 2484 EXPECT_EQ(0, WriteData(entry, 0, 0, buffer.get(), 0, true));
2477 EXPECT_EQ(0, WriteData(entry, 1, 10, buffer, 0, true)); 2485 EXPECT_EQ(0, WriteData(entry, 1, 10, buffer.get(), 0, true));
2478 2486
2479 // Delete the second buffer, writing 10 bytes to disk. 2487 // Delete the second buffer, writing 10 bytes to disk.
2480 entry->Close(); 2488 entry->Close();
2481 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); 2489 ASSERT_EQ(net::OK, OpenEntry(key, &entry));
2482 } 2490 }
2483 2491
2484 entry->Close(); 2492 entry->Close();
2485 EXPECT_EQ(0, cache_impl_->GetTotalBuffersSize()); 2493 EXPECT_EQ(0, cache_impl_->GetTotalBuffersSize());
2486 } 2494 }
2487 2495
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2568 // Ping the oldest entry. 2576 // Ping the oldest entry.
2569 cache_->OnExternalCacheHit("key0"); 2577 cache_->OnExternalCacheHit("key0");
2570 2578
2571 TrimForTest(false); 2579 TrimForTest(false);
2572 2580
2573 // Make sure the older key remains. 2581 // Make sure the older key remains.
2574 EXPECT_EQ(1, cache_->GetEntryCount()); 2582 EXPECT_EQ(1, cache_->GetEntryCount());
2575 ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); 2583 ASSERT_EQ(net::OK, OpenEntry("key0", &entry));
2576 entry->Close(); 2584 entry->Close();
2577 } 2585 }
OLDNEW
« no previous file with comments | « net/curvecp/test_server.cc ('k') | net/disk_cache/entry_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698