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/platform_thread.h" | 6 #include "base/platform_thread.h" |
7 #include "base/timer.h" | 7 #include "base/timer.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 : SyncIOTask(test, entry) {} | 69 : SyncIOTask(test, entry) {} |
70 | 70 |
71 virtual void Run() { | 71 virtual void Run() { |
72 test_->InternalSyncIOBackground(entry_); | 72 test_->InternalSyncIOBackground(entry_); |
73 } | 73 } |
74 }; | 74 }; |
75 | 75 |
76 // This part of the test runs on the background thread. | 76 // This part of the test runs on the background thread. |
77 void DiskCacheEntryTest::InternalSyncIOBackground(disk_cache::Entry* entry) { | 77 void DiskCacheEntryTest::InternalSyncIOBackground(disk_cache::Entry* entry) { |
78 const int kSize1 = 10; | 78 const int kSize1 = 10; |
79 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1); | 79 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize1)); |
80 CacheTestFillBuffer(buffer1->data(), kSize1, false); | 80 CacheTestFillBuffer(buffer1->data(), kSize1, false); |
81 EXPECT_EQ(0, entry->ReadData(0, 0, buffer1, kSize1, NULL)); | 81 EXPECT_EQ(0, entry->ReadData(0, 0, buffer1, kSize1, NULL)); |
82 base::strlcpy(buffer1->data(), "the data", kSize1); | 82 base::strlcpy(buffer1->data(), "the data", kSize1); |
83 EXPECT_EQ(10, entry->WriteData(0, 0, buffer1, kSize1, NULL, false)); | 83 EXPECT_EQ(10, entry->WriteData(0, 0, buffer1, kSize1, NULL, false)); |
84 memset(buffer1->data(), 0, kSize1); | 84 memset(buffer1->data(), 0, kSize1); |
85 EXPECT_EQ(10, entry->ReadData(0, 0, buffer1, kSize1, NULL)); | 85 EXPECT_EQ(10, entry->ReadData(0, 0, buffer1, kSize1, NULL)); |
86 EXPECT_STREQ("the data", buffer1->data()); | 86 EXPECT_STREQ("the data", buffer1->data()); |
87 | 87 |
88 const int kSize2 = 5000; | 88 const int kSize2 = 5000; |
89 const int kSize3 = 10000; | 89 const int kSize3 = 10000; |
90 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize2); | 90 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize2)); |
91 scoped_refptr<net::IOBuffer> buffer3 = new net::IOBuffer(kSize3); | 91 scoped_refptr<net::IOBuffer> buffer3(new net::IOBuffer(kSize3)); |
92 memset(buffer3->data(), 0, kSize3); | 92 memset(buffer3->data(), 0, kSize3); |
93 CacheTestFillBuffer(buffer2->data(), kSize2, false); | 93 CacheTestFillBuffer(buffer2->data(), kSize2, false); |
94 base::strlcpy(buffer2->data(), "The really big data goes here", kSize2); | 94 base::strlcpy(buffer2->data(), "The really big data goes here", kSize2); |
95 EXPECT_EQ(5000, entry->WriteData(1, 1500, buffer2, kSize2, NULL, false)); | 95 EXPECT_EQ(5000, entry->WriteData(1, 1500, buffer2, kSize2, NULL, false)); |
96 memset(buffer2->data(), 0, kSize2); | 96 memset(buffer2->data(), 0, kSize2); |
97 EXPECT_EQ(4989, entry->ReadData(1, 1511, buffer2, kSize2, NULL)); | 97 EXPECT_EQ(4989, entry->ReadData(1, 1511, buffer2, kSize2, NULL)); |
98 EXPECT_STREQ("big data goes here", buffer2->data()); | 98 EXPECT_STREQ("big data goes here", buffer2->data()); |
99 EXPECT_EQ(5000, entry->ReadData(1, 0, buffer2, kSize2, NULL)); | 99 EXPECT_EQ(5000, entry->ReadData(1, 0, buffer2, kSize2, NULL)); |
100 EXPECT_EQ(0, memcmp(buffer2->data(), buffer3->data(), 1500)); | 100 EXPECT_EQ(0, memcmp(buffer2->data(), buffer3->data(), 1500)); |
101 EXPECT_EQ(1500, entry->ReadData(1, 5000, buffer2, kSize2, NULL)); | 101 EXPECT_EQ(1500, entry->ReadData(1, 5000, buffer2, kSize2, NULL)); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 CallbackTest callback13(false); | 172 CallbackTest callback13(false); |
173 | 173 |
174 g_cache_tests_error = false; | 174 g_cache_tests_error = false; |
175 g_cache_tests_received = 0; | 175 g_cache_tests_received = 0; |
176 | 176 |
177 MessageLoopHelper helper; | 177 MessageLoopHelper helper; |
178 | 178 |
179 const int kSize1 = 10; | 179 const int kSize1 = 10; |
180 const int kSize2 = 5000; | 180 const int kSize2 = 5000; |
181 const int kSize3 = 10000; | 181 const int kSize3 = 10000; |
182 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1); | 182 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize1)); |
183 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize2); | 183 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize2)); |
184 scoped_refptr<net::IOBuffer> buffer3 = new net::IOBuffer(kSize3); | 184 scoped_refptr<net::IOBuffer> buffer3(new net::IOBuffer(kSize3)); |
185 CacheTestFillBuffer(buffer1->data(), kSize1, false); | 185 CacheTestFillBuffer(buffer1->data(), kSize1, false); |
186 CacheTestFillBuffer(buffer2->data(), kSize2, false); | 186 CacheTestFillBuffer(buffer2->data(), kSize2, false); |
187 CacheTestFillBuffer(buffer3->data(), kSize3, false); | 187 CacheTestFillBuffer(buffer3->data(), kSize3, false); |
188 | 188 |
189 EXPECT_EQ(0, entry->ReadData(0, 15 * 1024, buffer1, kSize1, &callback1)); | 189 EXPECT_EQ(0, entry->ReadData(0, 15 * 1024, buffer1, kSize1, &callback1)); |
190 base::strlcpy(buffer1->data(), "the data", kSize1); | 190 base::strlcpy(buffer1->data(), "the data", kSize1); |
191 int expected = 0; | 191 int expected = 0; |
192 int ret = entry->WriteData(0, 0, buffer1, kSize1, &callback2, false); | 192 int ret = entry->WriteData(0, 0, buffer1, kSize1, &callback2, false); |
193 EXPECT_TRUE(10 == ret || net::ERR_IO_PENDING == ret); | 193 EXPECT_TRUE(10 == ret || net::ERR_IO_PENDING == ret); |
194 if (net::ERR_IO_PENDING == ret) | 194 if (net::ERR_IO_PENDING == ret) |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 291 |
292 virtual void Run() { | 292 virtual void Run() { |
293 test_->ExternalSyncIOBackground(entry_); | 293 test_->ExternalSyncIOBackground(entry_); |
294 } | 294 } |
295 }; | 295 }; |
296 | 296 |
297 // This part of the test runs on the background thread. | 297 // This part of the test runs on the background thread. |
298 void DiskCacheEntryTest::ExternalSyncIOBackground(disk_cache::Entry* entry) { | 298 void DiskCacheEntryTest::ExternalSyncIOBackground(disk_cache::Entry* entry) { |
299 const int kSize1 = 17000; | 299 const int kSize1 = 17000; |
300 const int kSize2 = 25000; | 300 const int kSize2 = 25000; |
301 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1); | 301 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize1)); |
302 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize2); | 302 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize2)); |
303 CacheTestFillBuffer(buffer1->data(), kSize1, false); | 303 CacheTestFillBuffer(buffer1->data(), kSize1, false); |
304 CacheTestFillBuffer(buffer2->data(), kSize2, false); | 304 CacheTestFillBuffer(buffer2->data(), kSize2, false); |
305 base::strlcpy(buffer1->data(), "the data", kSize1); | 305 base::strlcpy(buffer1->data(), "the data", kSize1); |
306 EXPECT_EQ(17000, entry->WriteData(0, 0, buffer1, kSize1, NULL, false)); | 306 EXPECT_EQ(17000, entry->WriteData(0, 0, buffer1, kSize1, NULL, false)); |
307 memset(buffer1->data(), 0, kSize1); | 307 memset(buffer1->data(), 0, kSize1); |
308 EXPECT_EQ(17000, entry->ReadData(0, 0, buffer1, kSize1, NULL)); | 308 EXPECT_EQ(17000, entry->ReadData(0, 0, buffer1, kSize1, NULL)); |
309 EXPECT_STREQ("the data", buffer1->data()); | 309 EXPECT_STREQ("the data", buffer1->data()); |
310 | 310 |
311 base::strlcpy(buffer2->data(), "The really big data goes here", kSize2); | 311 base::strlcpy(buffer2->data(), "The really big data goes here", kSize2); |
312 EXPECT_EQ(25000, entry->WriteData(1, 10000, buffer2, kSize2, NULL, false)); | 312 EXPECT_EQ(25000, entry->WriteData(1, 10000, buffer2, kSize2, NULL, false)); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 | 376 |
377 g_cache_tests_error = false; | 377 g_cache_tests_error = false; |
378 g_cache_tests_received = 0; | 378 g_cache_tests_received = 0; |
379 int expected = 0; | 379 int expected = 0; |
380 | 380 |
381 MessageLoopHelper helper; | 381 MessageLoopHelper helper; |
382 | 382 |
383 const int kSize1 = 17000; | 383 const int kSize1 = 17000; |
384 const int kSize2 = 25000; | 384 const int kSize2 = 25000; |
385 const int kSize3 = 25000; | 385 const int kSize3 = 25000; |
386 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1); | 386 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize1)); |
387 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize2); | 387 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize2)); |
388 scoped_refptr<net::IOBuffer> buffer3 = new net::IOBuffer(kSize3); | 388 scoped_refptr<net::IOBuffer> buffer3(new net::IOBuffer(kSize3)); |
389 CacheTestFillBuffer(buffer1->data(), kSize1, false); | 389 CacheTestFillBuffer(buffer1->data(), kSize1, false); |
390 CacheTestFillBuffer(buffer2->data(), kSize2, false); | 390 CacheTestFillBuffer(buffer2->data(), kSize2, false); |
391 CacheTestFillBuffer(buffer3->data(), kSize3, false); | 391 CacheTestFillBuffer(buffer3->data(), kSize3, false); |
392 base::strlcpy(buffer1->data(), "the data", kSize1); | 392 base::strlcpy(buffer1->data(), "the data", kSize1); |
393 int ret = entry->WriteData(0, 0, buffer1, kSize1, &callback1, false); | 393 int ret = entry->WriteData(0, 0, buffer1, kSize1, &callback1, false); |
394 EXPECT_TRUE(17000 == ret || net::ERR_IO_PENDING == ret); | 394 EXPECT_TRUE(17000 == ret || net::ERR_IO_PENDING == ret); |
395 if (net::ERR_IO_PENDING == ret) | 395 if (net::ERR_IO_PENDING == ret) |
396 expected++; | 396 expected++; |
397 | 397 |
398 EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected)); | 398 EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected)); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 InitCache(); | 474 InitCache(); |
475 ExternalAsyncIO(); | 475 ExternalAsyncIO(); |
476 } | 476 } |
477 | 477 |
478 void DiskCacheEntryTest::StreamAccess() { | 478 void DiskCacheEntryTest::StreamAccess() { |
479 disk_cache::Entry* entry = NULL; | 479 disk_cache::Entry* entry = NULL; |
480 ASSERT_EQ(net::OK, CreateEntry("the first key", &entry)); | 480 ASSERT_EQ(net::OK, CreateEntry("the first key", &entry)); |
481 ASSERT_TRUE(NULL != entry); | 481 ASSERT_TRUE(NULL != entry); |
482 | 482 |
483 const int kBufferSize = 1024; | 483 const int kBufferSize = 1024; |
484 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kBufferSize); | 484 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kBufferSize)); |
485 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kBufferSize); | 485 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kBufferSize)); |
486 | 486 |
487 const int kNumStreams = 3; | 487 const int kNumStreams = 3; |
488 for (int i = 0; i < kNumStreams; i++) { | 488 for (int i = 0; i < kNumStreams; i++) { |
489 CacheTestFillBuffer(buffer1->data(), kBufferSize, false); | 489 CacheTestFillBuffer(buffer1->data(), kBufferSize, false); |
490 EXPECT_EQ(kBufferSize, WriteData(entry, i, 0, buffer1, kBufferSize, false)); | 490 EXPECT_EQ(kBufferSize, WriteData(entry, i, 0, buffer1, kBufferSize, false)); |
491 memset(buffer2->data(), 0, kBufferSize); | 491 memset(buffer2->data(), 0, kBufferSize); |
492 EXPECT_EQ(kBufferSize, ReadData(entry, i, 0, buffer2, kBufferSize)); | 492 EXPECT_EQ(kBufferSize, ReadData(entry, i, 0, buffer2, kBufferSize)); |
493 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kBufferSize)); | 493 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kBufferSize)); |
494 } | 494 } |
495 | 495 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 EXPECT_TRUE(entry->GetLastModified() < t2); | 572 EXPECT_TRUE(entry->GetLastModified() < t2); |
573 } else { | 573 } else { |
574 EXPECT_TRUE(entry->GetLastModified() >= t2); | 574 EXPECT_TRUE(entry->GetLastModified() >= t2); |
575 } | 575 } |
576 EXPECT_TRUE(entry->GetLastModified() == entry->GetLastUsed()); | 576 EXPECT_TRUE(entry->GetLastModified() == entry->GetLastUsed()); |
577 | 577 |
578 PlatformThread::Sleep(20); | 578 PlatformThread::Sleep(20); |
579 Time t3 = Time::Now(); | 579 Time t3 = Time::Now(); |
580 EXPECT_TRUE(t3 > t2); | 580 EXPECT_TRUE(t3 > t2); |
581 const int kSize = 200; | 581 const int kSize = 200; |
582 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); | 582 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); |
583 EXPECT_EQ(kSize, ReadData(entry, 0, 0, buffer, kSize)); | 583 EXPECT_EQ(kSize, ReadData(entry, 0, 0, buffer, kSize)); |
584 if (type_ == net::APP_CACHE) { | 584 if (type_ == net::APP_CACHE) { |
585 EXPECT_TRUE(entry->GetLastUsed() < t2); | 585 EXPECT_TRUE(entry->GetLastUsed() < t2); |
586 EXPECT_TRUE(entry->GetLastModified() < t2); | 586 EXPECT_TRUE(entry->GetLastModified() < t2); |
587 } else { | 587 } else { |
588 EXPECT_TRUE(entry->GetLastUsed() >= t3); | 588 EXPECT_TRUE(entry->GetLastUsed() >= t3); |
589 EXPECT_TRUE(entry->GetLastModified() < t3); | 589 EXPECT_TRUE(entry->GetLastModified() < t3); |
590 } | 590 } |
591 entry->Close(); | 591 entry->Close(); |
592 } | 592 } |
(...skipping 14 matching lines...) Expand all Loading... |
607 InitCache(); | 607 InitCache(); |
608 GetTimes(); | 608 GetTimes(); |
609 } | 609 } |
610 | 610 |
611 void DiskCacheEntryTest::GrowData() { | 611 void DiskCacheEntryTest::GrowData() { |
612 std::string key1("the first key"); | 612 std::string key1("the first key"); |
613 disk_cache::Entry* entry; | 613 disk_cache::Entry* entry; |
614 ASSERT_EQ(net::OK, CreateEntry(key1, &entry)); | 614 ASSERT_EQ(net::OK, CreateEntry(key1, &entry)); |
615 | 615 |
616 const int kSize = 20000; | 616 const int kSize = 20000; |
617 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); | 617 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); |
618 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize); | 618 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize)); |
619 CacheTestFillBuffer(buffer1->data(), kSize, false); | 619 CacheTestFillBuffer(buffer1->data(), kSize, false); |
620 memset(buffer2->data(), 0, kSize); | 620 memset(buffer2->data(), 0, kSize); |
621 | 621 |
622 base::strlcpy(buffer1->data(), "the data", kSize); | 622 base::strlcpy(buffer1->data(), "the data", kSize); |
623 EXPECT_EQ(10, WriteData(entry, 0, 0, buffer1, 10, false)); | 623 EXPECT_EQ(10, WriteData(entry, 0, 0, buffer1, 10, false)); |
624 EXPECT_EQ(10, ReadData(entry, 0, 0, buffer2, 10)); | 624 EXPECT_EQ(10, ReadData(entry, 0, 0, buffer2, 10)); |
625 EXPECT_STREQ("the data", buffer2->data()); | 625 EXPECT_STREQ("the data", buffer2->data()); |
626 EXPECT_EQ(10, entry->GetDataSize(0)); | 626 EXPECT_EQ(10, entry->GetDataSize(0)); |
627 | 627 |
628 EXPECT_EQ(2000, WriteData(entry, 0, 0, buffer1, 2000, false)); | 628 EXPECT_EQ(2000, WriteData(entry, 0, 0, buffer1, 2000, false)); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 GrowData(); | 692 GrowData(); |
693 } | 693 } |
694 | 694 |
695 void DiskCacheEntryTest::TruncateData() { | 695 void DiskCacheEntryTest::TruncateData() { |
696 std::string key("the first key"); | 696 std::string key("the first key"); |
697 disk_cache::Entry* entry; | 697 disk_cache::Entry* entry; |
698 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 698 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
699 | 699 |
700 const int kSize1 = 20000; | 700 const int kSize1 = 20000; |
701 const int kSize2 = 20000; | 701 const int kSize2 = 20000; |
702 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1); | 702 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize1)); |
703 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize2); | 703 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize2)); |
704 | 704 |
705 CacheTestFillBuffer(buffer1->data(), kSize1, false); | 705 CacheTestFillBuffer(buffer1->data(), kSize1, false); |
706 memset(buffer2->data(), 0, kSize2); | 706 memset(buffer2->data(), 0, kSize2); |
707 | 707 |
708 // Simple truncation: | 708 // Simple truncation: |
709 EXPECT_EQ(200, WriteData(entry, 0, 0, buffer1, 200, false)); | 709 EXPECT_EQ(200, WriteData(entry, 0, 0, buffer1, 200, false)); |
710 EXPECT_EQ(200, entry->GetDataSize(0)); | 710 EXPECT_EQ(200, entry->GetDataSize(0)); |
711 EXPECT_EQ(100, WriteData(entry, 0, 0, buffer1, 100, false)); | 711 EXPECT_EQ(100, WriteData(entry, 0, 0, buffer1, 100, false)); |
712 EXPECT_EQ(200, entry->GetDataSize(0)); | 712 EXPECT_EQ(200, entry->GetDataSize(0)); |
713 EXPECT_EQ(100, WriteData(entry, 0, 0, buffer1, 100, true)); | 713 EXPECT_EQ(100, WriteData(entry, 0, 0, buffer1, 100, true)); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 EXPECT_EQ(0, ReadData(entry, 0, 2000, NULL, 0)); | 794 EXPECT_EQ(0, ReadData(entry, 0, 2000, NULL, 0)); |
795 EXPECT_EQ(1000, entry->GetDataSize(0)); | 795 EXPECT_EQ(1000, entry->GetDataSize(0)); |
796 | 796 |
797 EXPECT_EQ(0, WriteData(entry, 0, 100000, NULL, 0, true)); | 797 EXPECT_EQ(0, WriteData(entry, 0, 100000, NULL, 0, true)); |
798 EXPECT_EQ(0, ReadData(entry, 0, 50000, NULL, 0)); | 798 EXPECT_EQ(0, ReadData(entry, 0, 50000, NULL, 0)); |
799 EXPECT_EQ(100000, entry->GetDataSize(0)); | 799 EXPECT_EQ(100000, entry->GetDataSize(0)); |
800 | 800 |
801 // Lets verify the actual content. | 801 // Lets verify the actual content. |
802 const int kSize = 20; | 802 const int kSize = 20; |
803 const char zeros[kSize] = {}; | 803 const char zeros[kSize] = {}; |
804 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); | 804 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); |
805 | 805 |
806 CacheTestFillBuffer(buffer->data(), kSize, false); | 806 CacheTestFillBuffer(buffer->data(), kSize, false); |
807 EXPECT_EQ(kSize, ReadData(entry, 0, 500, buffer, kSize)); | 807 EXPECT_EQ(kSize, ReadData(entry, 0, 500, buffer, kSize)); |
808 EXPECT_TRUE(!memcmp(buffer->data(), zeros, kSize)); | 808 EXPECT_TRUE(!memcmp(buffer->data(), zeros, kSize)); |
809 | 809 |
810 CacheTestFillBuffer(buffer->data(), kSize, false); | 810 CacheTestFillBuffer(buffer->data(), kSize, false); |
811 EXPECT_EQ(kSize, ReadData(entry, 0, 5000, buffer, kSize)); | 811 EXPECT_EQ(kSize, ReadData(entry, 0, 5000, buffer, kSize)); |
812 EXPECT_TRUE(!memcmp(buffer->data(), zeros, kSize)); | 812 EXPECT_TRUE(!memcmp(buffer->data(), zeros, kSize)); |
813 | 813 |
814 CacheTestFillBuffer(buffer->data(), kSize, false); | 814 CacheTestFillBuffer(buffer->data(), kSize, false); |
(...skipping 21 matching lines...) Expand all Loading... |
836 ZeroLengthIO(); | 836 ZeroLengthIO(); |
837 } | 837 } |
838 | 838 |
839 // Tests that we handle the content correctly when buffering. | 839 // Tests that we handle the content correctly when buffering. |
840 void DiskCacheEntryTest::Buffering() { | 840 void DiskCacheEntryTest::Buffering() { |
841 std::string key("the first key"); | 841 std::string key("the first key"); |
842 disk_cache::Entry* entry; | 842 disk_cache::Entry* entry; |
843 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 843 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
844 | 844 |
845 const int kSize = 200; | 845 const int kSize = 200; |
846 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); | 846 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); |
847 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize); | 847 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize)); |
848 CacheTestFillBuffer(buffer1->data(), kSize, true); | 848 CacheTestFillBuffer(buffer1->data(), kSize, true); |
849 CacheTestFillBuffer(buffer2->data(), kSize, true); | 849 CacheTestFillBuffer(buffer2->data(), kSize, true); |
850 | 850 |
851 EXPECT_EQ(kSize, WriteData(entry, 1, 0, buffer1, kSize, false)); | 851 EXPECT_EQ(kSize, WriteData(entry, 1, 0, buffer1, kSize, false)); |
852 entry->Close(); | 852 entry->Close(); |
853 | 853 |
854 // Write a little more and read what we wrote before. | 854 // Write a little more and read what we wrote before. |
855 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); | 855 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); |
856 EXPECT_EQ(kSize, WriteData(entry, 1, 5000, buffer1, kSize, false)); | 856 EXPECT_EQ(kSize, WriteData(entry, 1, 5000, buffer1, kSize, false)); |
857 EXPECT_EQ(kSize, ReadData(entry, 1, 0, buffer2, kSize)); | 857 EXPECT_EQ(kSize, ReadData(entry, 1, 0, buffer2, kSize)); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 | 917 |
918 // Some extra tests to make sure that buffering works properly when changing | 918 // Some extra tests to make sure that buffering works properly when changing |
919 // the entry size. | 919 // the entry size. |
920 void DiskCacheEntryTest::SizeChanges() { | 920 void DiskCacheEntryTest::SizeChanges() { |
921 std::string key("the first key"); | 921 std::string key("the first key"); |
922 disk_cache::Entry* entry; | 922 disk_cache::Entry* entry; |
923 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 923 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
924 | 924 |
925 const int kSize = 200; | 925 const int kSize = 200; |
926 const char zeros[kSize] = {}; | 926 const char zeros[kSize] = {}; |
927 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize); | 927 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); |
928 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize); | 928 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize)); |
929 CacheTestFillBuffer(buffer1->data(), kSize, true); | 929 CacheTestFillBuffer(buffer1->data(), kSize, true); |
930 CacheTestFillBuffer(buffer2->data(), kSize, true); | 930 CacheTestFillBuffer(buffer2->data(), kSize, true); |
931 | 931 |
932 EXPECT_EQ(kSize, WriteData(entry, 1, 0, buffer1, kSize, true)); | 932 EXPECT_EQ(kSize, WriteData(entry, 1, 0, buffer1, kSize, true)); |
933 EXPECT_EQ(kSize, WriteData(entry, 1, 17000, buffer1, kSize, true)); | 933 EXPECT_EQ(kSize, WriteData(entry, 1, 17000, buffer1, kSize, true)); |
934 EXPECT_EQ(kSize, WriteData(entry, 1, 23000, buffer1, kSize, true)); | 934 EXPECT_EQ(kSize, WriteData(entry, 1, 23000, buffer1, kSize, true)); |
935 entry->Close(); | 935 entry->Close(); |
936 | 936 |
937 // Extend the file and read between the old size and the new write. | 937 // Extend the file and read between the old size and the new write. |
938 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); | 938 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 // amount of bytes to write each time. | 1006 // amount of bytes to write each time. |
1007 void DiskCacheEntryTest::ReuseEntry(int size) { | 1007 void DiskCacheEntryTest::ReuseEntry(int size) { |
1008 std::string key1("the first key"); | 1008 std::string key1("the first key"); |
1009 disk_cache::Entry* entry; | 1009 disk_cache::Entry* entry; |
1010 ASSERT_EQ(net::OK, CreateEntry(key1, &entry)); | 1010 ASSERT_EQ(net::OK, CreateEntry(key1, &entry)); |
1011 | 1011 |
1012 entry->Close(); | 1012 entry->Close(); |
1013 std::string key2("the second key"); | 1013 std::string key2("the second key"); |
1014 ASSERT_EQ(net::OK, CreateEntry(key2, &entry)); | 1014 ASSERT_EQ(net::OK, CreateEntry(key2, &entry)); |
1015 | 1015 |
1016 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(size); | 1016 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(size)); |
1017 CacheTestFillBuffer(buffer->data(), size, false); | 1017 CacheTestFillBuffer(buffer->data(), size, false); |
1018 | 1018 |
1019 for (int i = 0; i < 15; i++) { | 1019 for (int i = 0; i < 15; i++) { |
1020 EXPECT_EQ(0, WriteData(entry, 0, 0, buffer, 0, true)); | 1020 EXPECT_EQ(0, WriteData(entry, 0, 0, buffer, 0, true)); |
1021 EXPECT_EQ(size, WriteData(entry, 0, 0, buffer, size, false)); | 1021 EXPECT_EQ(size, WriteData(entry, 0, 0, buffer, size, false)); |
1022 entry->Close(); | 1022 entry->Close(); |
1023 ASSERT_EQ(net::OK, OpenEntry(key2, &entry)); | 1023 ASSERT_EQ(net::OK, OpenEntry(key2, &entry)); |
1024 } | 1024 } |
1025 | 1025 |
1026 entry->Close(); | 1026 entry->Close(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 | 1060 |
1061 // Reading somewhere that was not written should return zeros. | 1061 // Reading somewhere that was not written should return zeros. |
1062 void DiskCacheEntryTest::InvalidData() { | 1062 void DiskCacheEntryTest::InvalidData() { |
1063 std::string key("the first key"); | 1063 std::string key("the first key"); |
1064 disk_cache::Entry* entry; | 1064 disk_cache::Entry* entry; |
1065 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1065 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
1066 | 1066 |
1067 const int kSize1 = 20000; | 1067 const int kSize1 = 20000; |
1068 const int kSize2 = 20000; | 1068 const int kSize2 = 20000; |
1069 const int kSize3 = 20000; | 1069 const int kSize3 = 20000; |
1070 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1); | 1070 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize1)); |
1071 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize2); | 1071 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize2)); |
1072 scoped_refptr<net::IOBuffer> buffer3 = new net::IOBuffer(kSize3); | 1072 scoped_refptr<net::IOBuffer> buffer3(new net::IOBuffer(kSize3)); |
1073 | 1073 |
1074 CacheTestFillBuffer(buffer1->data(), kSize1, false); | 1074 CacheTestFillBuffer(buffer1->data(), kSize1, false); |
1075 memset(buffer2->data(), 0, kSize2); | 1075 memset(buffer2->data(), 0, kSize2); |
1076 | 1076 |
1077 // Simple data grow: | 1077 // Simple data grow: |
1078 EXPECT_EQ(200, WriteData(entry, 0, 400, buffer1, 200, false)); | 1078 EXPECT_EQ(200, WriteData(entry, 0, 400, buffer1, 200, false)); |
1079 EXPECT_EQ(600, entry->GetDataSize(0)); | 1079 EXPECT_EQ(600, entry->GetDataSize(0)); |
1080 EXPECT_EQ(100, ReadData(entry, 0, 300, buffer3, 100)); | 1080 EXPECT_EQ(100, ReadData(entry, 0, 300, buffer3, 100)); |
1081 EXPECT_TRUE(!memcmp(buffer3->data(), buffer2->data(), 100)); | 1081 EXPECT_TRUE(!memcmp(buffer3->data(), buffer2->data(), 100)); |
1082 entry->Close(); | 1082 entry->Close(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 } | 1142 } |
1143 | 1143 |
1144 // Tests that the cache preserves the buffer of an IO operation. | 1144 // Tests that the cache preserves the buffer of an IO operation. |
1145 TEST_F(DiskCacheEntryTest, ReadWriteDestroyBuffer) { | 1145 TEST_F(DiskCacheEntryTest, ReadWriteDestroyBuffer) { |
1146 InitCache(); | 1146 InitCache(); |
1147 std::string key("the first key"); | 1147 std::string key("the first key"); |
1148 disk_cache::Entry* entry; | 1148 disk_cache::Entry* entry; |
1149 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1149 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
1150 | 1150 |
1151 const int kSize = 200; | 1151 const int kSize = 200; |
1152 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); | 1152 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); |
1153 CacheTestFillBuffer(buffer->data(), kSize, false); | 1153 CacheTestFillBuffer(buffer->data(), kSize, false); |
1154 | 1154 |
1155 TestCompletionCallback cb; | 1155 TestCompletionCallback cb; |
1156 EXPECT_EQ(net::ERR_IO_PENDING, | 1156 EXPECT_EQ(net::ERR_IO_PENDING, |
1157 entry->WriteData(0, 0, buffer, kSize, &cb, false)); | 1157 entry->WriteData(0, 0, buffer, kSize, &cb, false)); |
1158 | 1158 |
1159 // Release our reference to the buffer. | 1159 // Release our reference to the buffer. |
1160 buffer = NULL; | 1160 buffer = NULL; |
1161 EXPECT_EQ(kSize, cb.WaitForResult()); | 1161 EXPECT_EQ(kSize, cb.WaitForResult()); |
1162 | 1162 |
1163 // And now test with a Read(). | 1163 // And now test with a Read(). |
1164 buffer = new net::IOBuffer(kSize); | 1164 buffer = new net::IOBuffer(kSize); |
1165 CacheTestFillBuffer(buffer->data(), kSize, false); | 1165 CacheTestFillBuffer(buffer->data(), kSize, false); |
1166 | 1166 |
1167 EXPECT_EQ(net::ERR_IO_PENDING, entry->ReadData(0, 0, buffer, kSize, &cb)); | 1167 EXPECT_EQ(net::ERR_IO_PENDING, entry->ReadData(0, 0, buffer, kSize, &cb)); |
1168 buffer = NULL; | 1168 buffer = NULL; |
1169 EXPECT_EQ(kSize, cb.WaitForResult()); | 1169 EXPECT_EQ(kSize, cb.WaitForResult()); |
1170 | 1170 |
1171 entry->Close(); | 1171 entry->Close(); |
1172 } | 1172 } |
1173 | 1173 |
1174 void DiskCacheEntryTest::DoomNormalEntry() { | 1174 void DiskCacheEntryTest::DoomNormalEntry() { |
1175 std::string key("the first key"); | 1175 std::string key("the first key"); |
1176 disk_cache::Entry* entry; | 1176 disk_cache::Entry* entry; |
1177 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1177 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
1178 entry->Doom(); | 1178 entry->Doom(); |
1179 entry->Close(); | 1179 entry->Close(); |
1180 | 1180 |
1181 const int kSize = 20000; | 1181 const int kSize = 20000; |
1182 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kSize); | 1182 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kSize)); |
1183 CacheTestFillBuffer(buffer->data(), kSize, true); | 1183 CacheTestFillBuffer(buffer->data(), kSize, true); |
1184 buffer->data()[19999] = '\0'; | 1184 buffer->data()[19999] = '\0'; |
1185 | 1185 |
1186 key = buffer->data(); | 1186 key = buffer->data(); |
1187 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1187 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
1188 EXPECT_EQ(20000, WriteData(entry, 0, 0, buffer, kSize, false)); | 1188 EXPECT_EQ(20000, WriteData(entry, 0, 0, buffer, kSize, false)); |
1189 EXPECT_EQ(20000, WriteData(entry, 1, 0, buffer, kSize, false)); | 1189 EXPECT_EQ(20000, WriteData(entry, 1, 0, buffer, kSize, false)); |
1190 entry->Doom(); | 1190 entry->Doom(); |
1191 entry->Close(); | 1191 entry->Close(); |
1192 | 1192 |
(...skipping 20 matching lines...) Expand all Loading... |
1213 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1213 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
1214 entry->Doom(); | 1214 entry->Doom(); |
1215 | 1215 |
1216 FlushQueueForTest(); | 1216 FlushQueueForTest(); |
1217 EXPECT_EQ(0, cache_->GetEntryCount()); | 1217 EXPECT_EQ(0, cache_->GetEntryCount()); |
1218 Time initial = Time::Now(); | 1218 Time initial = Time::Now(); |
1219 PlatformThread::Sleep(20); | 1219 PlatformThread::Sleep(20); |
1220 | 1220 |
1221 const int kSize1 = 2000; | 1221 const int kSize1 = 2000; |
1222 const int kSize2 = 2000; | 1222 const int kSize2 = 2000; |
1223 scoped_refptr<net::IOBuffer> buffer1 = new net::IOBuffer(kSize1); | 1223 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize1)); |
1224 scoped_refptr<net::IOBuffer> buffer2 = new net::IOBuffer(kSize2); | 1224 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize2)); |
1225 CacheTestFillBuffer(buffer1->data(), kSize1, false); | 1225 CacheTestFillBuffer(buffer1->data(), kSize1, false); |
1226 memset(buffer2->data(), 0, kSize2); | 1226 memset(buffer2->data(), 0, kSize2); |
1227 | 1227 |
1228 EXPECT_EQ(2000, WriteData(entry, 0, 0, buffer1, 2000, false)); | 1228 EXPECT_EQ(2000, WriteData(entry, 0, 0, buffer1, 2000, false)); |
1229 EXPECT_EQ(2000, ReadData(entry, 0, 0, buffer2, 2000)); | 1229 EXPECT_EQ(2000, ReadData(entry, 0, 0, buffer2, 2000)); |
1230 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize1)); | 1230 EXPECT_EQ(0, memcmp(buffer1->data(), buffer2->data(), kSize1)); |
1231 EXPECT_EQ(key, entry->GetKey()); | 1231 EXPECT_EQ(key, entry->GetKey()); |
1232 EXPECT_TRUE(initial < entry->GetLastModified()); | 1232 EXPECT_TRUE(initial < entry->GetLastModified()); |
1233 EXPECT_TRUE(initial < entry->GetLastUsed()); | 1233 EXPECT_TRUE(initial < entry->GetLastUsed()); |
1234 | 1234 |
(...skipping 12 matching lines...) Expand all Loading... |
1247 DoomedEntry(); | 1247 DoomedEntry(); |
1248 } | 1248 } |
1249 | 1249 |
1250 // Test that child entries in a memory cache backend are not visible from | 1250 // Test that child entries in a memory cache backend are not visible from |
1251 // enumerations. | 1251 // enumerations. |
1252 TEST_F(DiskCacheEntryTest, MemoryOnlyEnumerationWithSparseEntries) { | 1252 TEST_F(DiskCacheEntryTest, MemoryOnlyEnumerationWithSparseEntries) { |
1253 SetMemoryOnlyMode(); | 1253 SetMemoryOnlyMode(); |
1254 InitCache(); | 1254 InitCache(); |
1255 | 1255 |
1256 const int kSize = 4096; | 1256 const int kSize = 4096; |
1257 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize); | 1257 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); |
1258 CacheTestFillBuffer(buf->data(), kSize, false); | 1258 CacheTestFillBuffer(buf->data(), kSize, false); |
1259 | 1259 |
1260 std::string key("the first key"); | 1260 std::string key("the first key"); |
1261 disk_cache::Entry* parent_entry; | 1261 disk_cache::Entry* parent_entry; |
1262 ASSERT_EQ(net::OK, CreateEntry(key, &parent_entry)); | 1262 ASSERT_EQ(net::OK, CreateEntry(key, &parent_entry)); |
1263 | 1263 |
1264 // Writes to the parent entry. | 1264 // Writes to the parent entry. |
1265 EXPECT_EQ(kSize, parent_entry->WriteSparseData(0, buf, kSize, NULL)); | 1265 EXPECT_EQ(kSize, parent_entry->WriteSparseData(0, buf, kSize, NULL)); |
1266 | 1266 |
1267 // This write creates a child entry and writes to it. | 1267 // This write creates a child entry and writes to it. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1301 | 1301 |
1302 EXPECT_EQ(0, memcmp(buf_1->data(), buf_2->data(), size)); | 1302 EXPECT_EQ(0, memcmp(buf_1->data(), buf_2->data(), size)); |
1303 } | 1303 } |
1304 | 1304 |
1305 // Reads |size| bytes from |entry| at |offset| and verifies that they are the | 1305 // Reads |size| bytes from |entry| at |offset| and verifies that they are the |
1306 // same as the content of the provided |buffer|. | 1306 // same as the content of the provided |buffer|. |
1307 void VerifyContentSparseIO(disk_cache::Entry* entry, int64 offset, char* buffer, | 1307 void VerifyContentSparseIO(disk_cache::Entry* entry, int64 offset, char* buffer, |
1308 int size) { | 1308 int size) { |
1309 TestCompletionCallback cb; | 1309 TestCompletionCallback cb; |
1310 | 1310 |
1311 scoped_refptr<net::IOBuffer> buf_1 = new net::IOBuffer(size); | 1311 scoped_refptr<net::IOBuffer> buf_1(new net::IOBuffer(size)); |
1312 memset(buf_1->data(), 0, size); | 1312 memset(buf_1->data(), 0, size); |
1313 int ret = entry->ReadSparseData(offset, buf_1, size, &cb); | 1313 int ret = entry->ReadSparseData(offset, buf_1, size, &cb); |
1314 EXPECT_EQ(size, cb.GetResult(ret)); | 1314 EXPECT_EQ(size, cb.GetResult(ret)); |
1315 | 1315 |
1316 EXPECT_EQ(0, memcmp(buf_1->data(), buffer, size)); | 1316 EXPECT_EQ(0, memcmp(buf_1->data(), buffer, size)); |
1317 } | 1317 } |
1318 | 1318 |
1319 void DiskCacheEntryTest::BasicSparseIO() { | 1319 void DiskCacheEntryTest::BasicSparseIO() { |
1320 std::string key("the first key"); | 1320 std::string key("the first key"); |
1321 disk_cache::Entry* entry; | 1321 disk_cache::Entry* entry; |
1322 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1322 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
1323 | 1323 |
1324 const int kSize = 2048; | 1324 const int kSize = 2048; |
1325 scoped_refptr<net::IOBuffer> buf_1 = new net::IOBuffer(kSize); | 1325 scoped_refptr<net::IOBuffer> buf_1(new net::IOBuffer(kSize)); |
1326 scoped_refptr<net::IOBuffer> buf_2 = new net::IOBuffer(kSize); | 1326 scoped_refptr<net::IOBuffer> buf_2(new net::IOBuffer(kSize)); |
1327 CacheTestFillBuffer(buf_1->data(), kSize, false); | 1327 CacheTestFillBuffer(buf_1->data(), kSize, false); |
1328 | 1328 |
1329 // Write at offset 0. | 1329 // Write at offset 0. |
1330 VerifySparseIO(entry, 0, buf_1, kSize, buf_2); | 1330 VerifySparseIO(entry, 0, buf_1, kSize, buf_2); |
1331 | 1331 |
1332 // Write at offset 0x400000 (4 MB). | 1332 // Write at offset 0x400000 (4 MB). |
1333 VerifySparseIO(entry, 0x400000, buf_1, kSize, buf_2); | 1333 VerifySparseIO(entry, 0x400000, buf_1, kSize, buf_2); |
1334 | 1334 |
1335 // Write at offset 0x800000000 (32 GB). | 1335 // Write at offset 0x800000000 (32 GB). |
1336 VerifySparseIO(entry, 0x800000000LL, buf_1, kSize, buf_2); | 1336 VerifySparseIO(entry, 0x800000000LL, buf_1, kSize, buf_2); |
(...skipping 19 matching lines...) Expand all Loading... |
1356 BasicSparseIO(); | 1356 BasicSparseIO(); |
1357 } | 1357 } |
1358 | 1358 |
1359 void DiskCacheEntryTest::HugeSparseIO() { | 1359 void DiskCacheEntryTest::HugeSparseIO() { |
1360 std::string key("the first key"); | 1360 std::string key("the first key"); |
1361 disk_cache::Entry* entry; | 1361 disk_cache::Entry* entry; |
1362 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1362 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
1363 | 1363 |
1364 // Write 1.2 MB so that we cover multiple entries. | 1364 // Write 1.2 MB so that we cover multiple entries. |
1365 const int kSize = 1200 * 1024; | 1365 const int kSize = 1200 * 1024; |
1366 scoped_refptr<net::IOBuffer> buf_1 = new net::IOBuffer(kSize); | 1366 scoped_refptr<net::IOBuffer> buf_1(new net::IOBuffer(kSize)); |
1367 scoped_refptr<net::IOBuffer> buf_2 = new net::IOBuffer(kSize); | 1367 scoped_refptr<net::IOBuffer> buf_2(new net::IOBuffer(kSize)); |
1368 CacheTestFillBuffer(buf_1->data(), kSize, false); | 1368 CacheTestFillBuffer(buf_1->data(), kSize, false); |
1369 | 1369 |
1370 // Write at offset 0x20F0000 (33 MB - 64 KB). | 1370 // Write at offset 0x20F0000 (33 MB - 64 KB). |
1371 VerifySparseIO(entry, 0x20F0000, buf_1, kSize, buf_2); | 1371 VerifySparseIO(entry, 0x20F0000, buf_1, kSize, buf_2); |
1372 entry->Close(); | 1372 entry->Close(); |
1373 | 1373 |
1374 // Check it again. | 1374 // Check it again. |
1375 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); | 1375 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); |
1376 VerifyContentSparseIO(entry, 0x20F0000, buf_1->data(), kSize); | 1376 VerifyContentSparseIO(entry, 0x20F0000, buf_1->data(), kSize); |
1377 entry->Close(); | 1377 entry->Close(); |
1378 } | 1378 } |
1379 | 1379 |
1380 TEST_F(DiskCacheEntryTest, HugeSparseIO) { | 1380 TEST_F(DiskCacheEntryTest, HugeSparseIO) { |
1381 InitCache(); | 1381 InitCache(); |
1382 HugeSparseIO(); | 1382 HugeSparseIO(); |
1383 } | 1383 } |
1384 | 1384 |
1385 TEST_F(DiskCacheEntryTest, MemoryOnlyHugeSparseIO) { | 1385 TEST_F(DiskCacheEntryTest, MemoryOnlyHugeSparseIO) { |
1386 SetMemoryOnlyMode(); | 1386 SetMemoryOnlyMode(); |
1387 InitCache(); | 1387 InitCache(); |
1388 HugeSparseIO(); | 1388 HugeSparseIO(); |
1389 } | 1389 } |
1390 | 1390 |
1391 void DiskCacheEntryTest::GetAvailableRange() { | 1391 void DiskCacheEntryTest::GetAvailableRange() { |
1392 std::string key("the first key"); | 1392 std::string key("the first key"); |
1393 disk_cache::Entry* entry; | 1393 disk_cache::Entry* entry; |
1394 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1394 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
1395 | 1395 |
1396 const int kSize = 16 * 1024; | 1396 const int kSize = 16 * 1024; |
1397 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize); | 1397 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); |
1398 CacheTestFillBuffer(buf->data(), kSize, false); | 1398 CacheTestFillBuffer(buf->data(), kSize, false); |
1399 | 1399 |
1400 // Write at offset 0x20F0000 (33 MB - 64 KB), and 0x20F4400 (33 MB - 47 KB). | 1400 // Write at offset 0x20F0000 (33 MB - 64 KB), and 0x20F4400 (33 MB - 47 KB). |
1401 EXPECT_EQ(kSize, WriteSparseData(entry, 0x20F0000, buf, kSize)); | 1401 EXPECT_EQ(kSize, WriteSparseData(entry, 0x20F0000, buf, kSize)); |
1402 EXPECT_EQ(kSize, WriteSparseData(entry, 0x20F4400, buf, kSize)); | 1402 EXPECT_EQ(kSize, WriteSparseData(entry, 0x20F4400, buf, kSize)); |
1403 | 1403 |
1404 // We stop at the first empty block. | 1404 // We stop at the first empty block. |
1405 int64 start; | 1405 int64 start; |
1406 TestCompletionCallback cb; | 1406 TestCompletionCallback cb; |
1407 int rv = entry->GetAvailableRange(0x20F0000, kSize * 2, &start, &cb); | 1407 int rv = entry->GetAvailableRange(0x20F0000, kSize * 2, &start, &cb); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1449 InitCache(); | 1449 InitCache(); |
1450 GetAvailableRange(); | 1450 GetAvailableRange(); |
1451 } | 1451 } |
1452 | 1452 |
1453 void DiskCacheEntryTest::CouldBeSparse() { | 1453 void DiskCacheEntryTest::CouldBeSparse() { |
1454 std::string key("the first key"); | 1454 std::string key("the first key"); |
1455 disk_cache::Entry* entry; | 1455 disk_cache::Entry* entry; |
1456 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1456 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
1457 | 1457 |
1458 const int kSize = 16 * 1024; | 1458 const int kSize = 16 * 1024; |
1459 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize); | 1459 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); |
1460 CacheTestFillBuffer(buf->data(), kSize, false); | 1460 CacheTestFillBuffer(buf->data(), kSize, false); |
1461 | 1461 |
1462 // Write at offset 0x20F0000 (33 MB - 64 KB). | 1462 // Write at offset 0x20F0000 (33 MB - 64 KB). |
1463 EXPECT_EQ(kSize, WriteSparseData(entry, 0x20F0000, buf, kSize)); | 1463 EXPECT_EQ(kSize, WriteSparseData(entry, 0x20F0000, buf, kSize)); |
1464 | 1464 |
1465 EXPECT_TRUE(entry->CouldBeSparse()); | 1465 EXPECT_TRUE(entry->CouldBeSparse()); |
1466 entry->Close(); | 1466 entry->Close(); |
1467 | 1467 |
1468 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); | 1468 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); |
1469 EXPECT_TRUE(entry->CouldBeSparse()); | 1469 EXPECT_TRUE(entry->CouldBeSparse()); |
(...skipping 25 matching lines...) Expand all Loading... |
1495 SetMemoryOnlyMode(); | 1495 SetMemoryOnlyMode(); |
1496 InitCache(); | 1496 InitCache(); |
1497 CouldBeSparse(); | 1497 CouldBeSparse(); |
1498 } | 1498 } |
1499 | 1499 |
1500 TEST_F(DiskCacheEntryTest, MemoryOnlyMisalignedSparseIO) { | 1500 TEST_F(DiskCacheEntryTest, MemoryOnlyMisalignedSparseIO) { |
1501 SetMemoryOnlyMode(); | 1501 SetMemoryOnlyMode(); |
1502 InitCache(); | 1502 InitCache(); |
1503 | 1503 |
1504 const int kSize = 8192; | 1504 const int kSize = 8192; |
1505 scoped_refptr<net::IOBuffer> buf_1 = new net::IOBuffer(kSize); | 1505 scoped_refptr<net::IOBuffer> buf_1(new net::IOBuffer(kSize)); |
1506 scoped_refptr<net::IOBuffer> buf_2 = new net::IOBuffer(kSize); | 1506 scoped_refptr<net::IOBuffer> buf_2(new net::IOBuffer(kSize)); |
1507 CacheTestFillBuffer(buf_1->data(), kSize, false); | 1507 CacheTestFillBuffer(buf_1->data(), kSize, false); |
1508 | 1508 |
1509 std::string key("the first key"); | 1509 std::string key("the first key"); |
1510 disk_cache::Entry* entry; | 1510 disk_cache::Entry* entry; |
1511 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1511 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
1512 | 1512 |
1513 // This loop writes back to back starting from offset 0 and 9000. | 1513 // This loop writes back to back starting from offset 0 and 9000. |
1514 for (int i = 0; i < kSize; i += 1024) { | 1514 for (int i = 0; i < kSize; i += 1024) { |
1515 scoped_refptr<net::WrappedIOBuffer> buf_3 = | 1515 scoped_refptr<net::WrappedIOBuffer> buf_3( |
1516 new net::WrappedIOBuffer(buf_1->data() + i); | 1516 new net::WrappedIOBuffer(buf_1->data() + i)); |
1517 VerifySparseIO(entry, i, buf_3, 1024, buf_2); | 1517 VerifySparseIO(entry, i, buf_3, 1024, buf_2); |
1518 VerifySparseIO(entry, 9000 + i, buf_3, 1024, buf_2); | 1518 VerifySparseIO(entry, 9000 + i, buf_3, 1024, buf_2); |
1519 } | 1519 } |
1520 | 1520 |
1521 // Make sure we have data written. | 1521 // Make sure we have data written. |
1522 VerifyContentSparseIO(entry, 0, buf_1->data(), kSize); | 1522 VerifyContentSparseIO(entry, 0, buf_1->data(), kSize); |
1523 VerifyContentSparseIO(entry, 9000, buf_1->data(), kSize); | 1523 VerifyContentSparseIO(entry, 9000, buf_1->data(), kSize); |
1524 | 1524 |
1525 // This tests a large write that spans 3 entries from a misaligned offset. | 1525 // This tests a large write that spans 3 entries from a misaligned offset. |
1526 VerifySparseIO(entry, 20481, buf_1, 8192, buf_2); | 1526 VerifySparseIO(entry, 20481, buf_1, 8192, buf_2); |
1527 | 1527 |
1528 entry->Close(); | 1528 entry->Close(); |
1529 } | 1529 } |
1530 | 1530 |
1531 TEST_F(DiskCacheEntryTest, MemoryOnlyMisalignedGetAvailableRange) { | 1531 TEST_F(DiskCacheEntryTest, MemoryOnlyMisalignedGetAvailableRange) { |
1532 SetMemoryOnlyMode(); | 1532 SetMemoryOnlyMode(); |
1533 InitCache(); | 1533 InitCache(); |
1534 | 1534 |
1535 const int kSize = 8192; | 1535 const int kSize = 8192; |
1536 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize); | 1536 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); |
1537 CacheTestFillBuffer(buf->data(), kSize, false); | 1537 CacheTestFillBuffer(buf->data(), kSize, false); |
1538 | 1538 |
1539 disk_cache::Entry* entry; | 1539 disk_cache::Entry* entry; |
1540 std::string key("the first key"); | 1540 std::string key("the first key"); |
1541 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1541 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
1542 | 1542 |
1543 // Writes in the middle of an entry. | 1543 // Writes in the middle of an entry. |
1544 EXPECT_EQ(1024, entry->WriteSparseData(0, buf, 1024, NULL)); | 1544 EXPECT_EQ(1024, entry->WriteSparseData(0, buf, 1024, NULL)); |
1545 EXPECT_EQ(1024, entry->WriteSparseData(5120, buf, 1024, NULL)); | 1545 EXPECT_EQ(1024, entry->WriteSparseData(5120, buf, 1024, NULL)); |
1546 EXPECT_EQ(1024, entry->WriteSparseData(10000, buf, 1024, NULL)); | 1546 EXPECT_EQ(1024, entry->WriteSparseData(10000, buf, 1024, NULL)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 } | 1587 } |
1588 | 1588 |
1589 void DiskCacheEntryTest::DoomSparseEntry() { | 1589 void DiskCacheEntryTest::DoomSparseEntry() { |
1590 std::string key1("the first key"); | 1590 std::string key1("the first key"); |
1591 std::string key2("the second key"); | 1591 std::string key2("the second key"); |
1592 disk_cache::Entry *entry1, *entry2; | 1592 disk_cache::Entry *entry1, *entry2; |
1593 ASSERT_EQ(net::OK, CreateEntry(key1, &entry1)); | 1593 ASSERT_EQ(net::OK, CreateEntry(key1, &entry1)); |
1594 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2)); | 1594 ASSERT_EQ(net::OK, CreateEntry(key2, &entry2)); |
1595 | 1595 |
1596 const int kSize = 4 * 1024; | 1596 const int kSize = 4 * 1024; |
1597 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize); | 1597 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); |
1598 CacheTestFillBuffer(buf->data(), kSize, false); | 1598 CacheTestFillBuffer(buf->data(), kSize, false); |
1599 | 1599 |
1600 int64 offset = 1024; | 1600 int64 offset = 1024; |
1601 // Write to a bunch of ranges. | 1601 // Write to a bunch of ranges. |
1602 for (int i = 0; i < 12; i++) { | 1602 for (int i = 0; i < 12; i++) { |
1603 EXPECT_EQ(kSize, entry1->WriteSparseData(offset, buf, kSize, NULL)); | 1603 EXPECT_EQ(kSize, entry1->WriteSparseData(offset, buf, kSize, NULL)); |
1604 // Keep the second map under the default size. | 1604 // Keep the second map under the default size. |
1605 if (i < 9) | 1605 if (i < 9) |
1606 EXPECT_EQ(kSize, entry2->WriteSparseData(offset, buf, kSize, NULL)); | 1606 EXPECT_EQ(kSize, entry2->WriteSparseData(offset, buf, kSize, NULL)); |
1607 offset *= 4; | 1607 offset *= 4; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1674 // deleting the sub-entries of a sparse entry. | 1674 // deleting the sub-entries of a sparse entry. |
1675 TEST_F(DiskCacheEntryTest, DoomSparseEntry2) { | 1675 TEST_F(DiskCacheEntryTest, DoomSparseEntry2) { |
1676 SetDirectMode(); | 1676 SetDirectMode(); |
1677 UseCurrentThread(); | 1677 UseCurrentThread(); |
1678 InitCache(); | 1678 InitCache(); |
1679 std::string key("the key"); | 1679 std::string key("the key"); |
1680 disk_cache::Entry* entry; | 1680 disk_cache::Entry* entry; |
1681 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1681 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
1682 | 1682 |
1683 const int kSize = 4 * 1024; | 1683 const int kSize = 4 * 1024; |
1684 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize); | 1684 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); |
1685 CacheTestFillBuffer(buf->data(), kSize, false); | 1685 CacheTestFillBuffer(buf->data(), kSize, false); |
1686 | 1686 |
1687 int64 offset = 1024; | 1687 int64 offset = 1024; |
1688 // Write to a bunch of ranges. | 1688 // Write to a bunch of ranges. |
1689 for (int i = 0; i < 12; i++) { | 1689 for (int i = 0; i < 12; i++) { |
1690 EXPECT_EQ(kSize, entry->WriteSparseData(offset, buf, kSize, NULL)); | 1690 EXPECT_EQ(kSize, entry->WriteSparseData(offset, buf, kSize, NULL)); |
1691 offset *= 4; | 1691 offset *= 4; |
1692 } | 1692 } |
1693 EXPECT_EQ(9, cache_->GetEntryCount()); | 1693 EXPECT_EQ(9, cache_->GetEntryCount()); |
1694 | 1694 |
1695 entry->Close(); | 1695 entry->Close(); |
1696 SparseTestCompletionCallback cb(cache_); | 1696 SparseTestCompletionCallback cb(cache_); |
1697 int rv = cache_->DoomEntry(key, &cb); | 1697 int rv = cache_->DoomEntry(key, &cb); |
1698 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 1698 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
1699 EXPECT_EQ(net::OK, cb.WaitForResult()); | 1699 EXPECT_EQ(net::OK, cb.WaitForResult()); |
1700 | 1700 |
1701 // TearDown will attempt to delete the cache_. | 1701 // TearDown will attempt to delete the cache_. |
1702 cache_ = NULL; | 1702 cache_ = NULL; |
1703 } | 1703 } |
1704 | 1704 |
1705 void DiskCacheEntryTest::PartialSparseEntry() { | 1705 void DiskCacheEntryTest::PartialSparseEntry() { |
1706 std::string key("the first key"); | 1706 std::string key("the first key"); |
1707 disk_cache::Entry* entry; | 1707 disk_cache::Entry* entry; |
1708 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1708 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
1709 | 1709 |
1710 // We should be able to deal with IO that is not aligned to the block size | 1710 // We should be able to deal with IO that is not aligned to the block size |
1711 // of a sparse entry, at least to write a big range without leaving holes. | 1711 // of a sparse entry, at least to write a big range without leaving holes. |
1712 const int kSize = 4 * 1024; | 1712 const int kSize = 4 * 1024; |
1713 const int kSmallSize = 128; | 1713 const int kSmallSize = 128; |
1714 scoped_refptr<net::IOBuffer> buf1 = new net::IOBuffer(kSize); | 1714 scoped_refptr<net::IOBuffer> buf1(new net::IOBuffer(kSize)); |
1715 CacheTestFillBuffer(buf1->data(), kSize, false); | 1715 CacheTestFillBuffer(buf1->data(), kSize, false); |
1716 | 1716 |
1717 // The first write is just to extend the entry. The third write occupies | 1717 // The first write is just to extend the entry. The third write occupies |
1718 // a 1KB block partially, it may not be written internally depending on the | 1718 // a 1KB block partially, it may not be written internally depending on the |
1719 // implementation. | 1719 // implementation. |
1720 EXPECT_EQ(kSize, WriteSparseData(entry, 20000, buf1, kSize)); | 1720 EXPECT_EQ(kSize, WriteSparseData(entry, 20000, buf1, kSize)); |
1721 EXPECT_EQ(kSize, WriteSparseData(entry, 500, buf1, kSize)); | 1721 EXPECT_EQ(kSize, WriteSparseData(entry, 500, buf1, kSize)); |
1722 EXPECT_EQ(kSmallSize, WriteSparseData(entry, 1080321, buf1, kSmallSize)); | 1722 EXPECT_EQ(kSmallSize, WriteSparseData(entry, 1080321, buf1, kSmallSize)); |
1723 entry->Close(); | 1723 entry->Close(); |
1724 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); | 1724 ASSERT_EQ(net::OK, OpenEntry(key, &entry)); |
1725 | 1725 |
1726 scoped_refptr<net::IOBuffer> buf2 = new net::IOBuffer(kSize); | 1726 scoped_refptr<net::IOBuffer> buf2(new net::IOBuffer(kSize)); |
1727 memset(buf2->data(), 0, kSize); | 1727 memset(buf2->data(), 0, kSize); |
1728 EXPECT_EQ(0, ReadSparseData(entry, 8000, buf2, kSize)); | 1728 EXPECT_EQ(0, ReadSparseData(entry, 8000, buf2, kSize)); |
1729 | 1729 |
1730 EXPECT_EQ(500, ReadSparseData(entry, kSize, buf2, kSize)); | 1730 EXPECT_EQ(500, ReadSparseData(entry, kSize, buf2, kSize)); |
1731 EXPECT_EQ(0, memcmp(buf2->data(), buf1->data() + kSize - 500, 500)); | 1731 EXPECT_EQ(0, memcmp(buf2->data(), buf1->data() + kSize - 500, 500)); |
1732 EXPECT_EQ(0, ReadSparseData(entry, 0, buf2, kSize)); | 1732 EXPECT_EQ(0, ReadSparseData(entry, 0, buf2, kSize)); |
1733 | 1733 |
1734 // This read should not change anything. | 1734 // This read should not change anything. |
1735 EXPECT_EQ(96, ReadSparseData(entry, 24000, buf2, kSize)); | 1735 EXPECT_EQ(96, ReadSparseData(entry, 24000, buf2, kSize)); |
1736 EXPECT_EQ(500, ReadSparseData(entry, kSize, buf2, kSize)); | 1736 EXPECT_EQ(500, ReadSparseData(entry, kSize, buf2, kSize)); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1798 } | 1798 } |
1799 | 1799 |
1800 // Tests that corrupt sparse children are removed automatically. | 1800 // Tests that corrupt sparse children are removed automatically. |
1801 TEST_F(DiskCacheEntryTest, CleanupSparseEntry) { | 1801 TEST_F(DiskCacheEntryTest, CleanupSparseEntry) { |
1802 InitCache(); | 1802 InitCache(); |
1803 std::string key("the first key"); | 1803 std::string key("the first key"); |
1804 disk_cache::Entry* entry; | 1804 disk_cache::Entry* entry; |
1805 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1805 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
1806 | 1806 |
1807 const int kSize = 4 * 1024; | 1807 const int kSize = 4 * 1024; |
1808 scoped_refptr<net::IOBuffer> buf1 = new net::IOBuffer(kSize); | 1808 scoped_refptr<net::IOBuffer> buf1(new net::IOBuffer(kSize)); |
1809 CacheTestFillBuffer(buf1->data(), kSize, false); | 1809 CacheTestFillBuffer(buf1->data(), kSize, false); |
1810 | 1810 |
1811 const int k1Meg = 1024 * 1024; | 1811 const int k1Meg = 1024 * 1024; |
1812 EXPECT_EQ(kSize, WriteSparseData(entry, 8192, buf1, kSize)); | 1812 EXPECT_EQ(kSize, WriteSparseData(entry, 8192, buf1, kSize)); |
1813 EXPECT_EQ(kSize, WriteSparseData(entry, k1Meg + 8192, buf1, kSize)); | 1813 EXPECT_EQ(kSize, WriteSparseData(entry, k1Meg + 8192, buf1, kSize)); |
1814 EXPECT_EQ(kSize, WriteSparseData(entry, 2 * k1Meg + 8192, buf1, kSize)); | 1814 EXPECT_EQ(kSize, WriteSparseData(entry, 2 * k1Meg + 8192, buf1, kSize)); |
1815 entry->Close(); | 1815 entry->Close(); |
1816 EXPECT_EQ(4, cache_->GetEntryCount()); | 1816 EXPECT_EQ(4, cache_->GetEntryCount()); |
1817 | 1817 |
1818 void* iter = NULL; | 1818 void* iter = NULL; |
(...skipping 30 matching lines...) Expand all Loading... |
1849 } | 1849 } |
1850 | 1850 |
1851 TEST_F(DiskCacheEntryTest, CancelSparseIO) { | 1851 TEST_F(DiskCacheEntryTest, CancelSparseIO) { |
1852 UseCurrentThread(); | 1852 UseCurrentThread(); |
1853 InitCache(); | 1853 InitCache(); |
1854 std::string key("the first key"); | 1854 std::string key("the first key"); |
1855 disk_cache::Entry* entry; | 1855 disk_cache::Entry* entry; |
1856 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | 1856 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); |
1857 | 1857 |
1858 const int kSize = 40 * 1024; | 1858 const int kSize = 40 * 1024; |
1859 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize); | 1859 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); |
1860 CacheTestFillBuffer(buf->data(), kSize, false); | 1860 CacheTestFillBuffer(buf->data(), kSize, false); |
1861 | 1861 |
1862 // This will open and write two "real" entries. | 1862 // This will open and write two "real" entries. |
1863 TestCompletionCallback cb1, cb2, cb3, cb4, cb5; | 1863 TestCompletionCallback cb1, cb2, cb3, cb4, cb5; |
1864 int rv = entry->WriteSparseData(1024 * 1024 - 4096, buf, kSize, &cb1); | 1864 int rv = entry->WriteSparseData(1024 * 1024 - 4096, buf, kSize, &cb1); |
1865 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 1865 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
1866 | 1866 |
1867 int64 offset = 0; | 1867 int64 offset = 0; |
1868 rv = entry->GetAvailableRange(offset, kSize, &offset, &cb5); | 1868 rv = entry->GetAvailableRange(offset, kSize, &offset, &cb5); |
1869 rv = cb5.GetResult(rv); | 1869 rv = cb5.GetResult(rv); |
(...skipping 22 matching lines...) Expand all Loading... |
1892 rv = cb1.WaitForResult(); | 1892 rv = cb1.WaitForResult(); |
1893 EXPECT_TRUE(rv == 4096 || rv == kSize); | 1893 EXPECT_TRUE(rv == 4096 || rv == kSize); |
1894 EXPECT_EQ(net::OK, cb2.WaitForResult()); | 1894 EXPECT_EQ(net::OK, cb2.WaitForResult()); |
1895 EXPECT_EQ(net::OK, cb3.WaitForResult()); | 1895 EXPECT_EQ(net::OK, cb3.WaitForResult()); |
1896 EXPECT_EQ(net::OK, cb4.WaitForResult()); | 1896 EXPECT_EQ(net::OK, cb4.WaitForResult()); |
1897 | 1897 |
1898 rv = entry->GetAvailableRange(offset, kSize, &offset, &cb5); | 1898 rv = entry->GetAvailableRange(offset, kSize, &offset, &cb5); |
1899 EXPECT_EQ(0, cb5.GetResult(rv)); | 1899 EXPECT_EQ(0, cb5.GetResult(rv)); |
1900 entry->Close(); | 1900 entry->Close(); |
1901 } | 1901 } |
OLD | NEW |