| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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" |
| 11 #include "net/base/test_completion_callback.h" |
| 11 #include "net/disk_cache/disk_cache_test_base.h" | 12 #include "net/disk_cache/disk_cache_test_base.h" |
| 12 #include "net/disk_cache/disk_cache_test_util.h" | 13 #include "net/disk_cache/disk_cache_test_util.h" |
| 13 #include "net/disk_cache/entry_impl.h" | 14 #include "net/disk_cache/entry_impl.h" |
| 14 #include "net/disk_cache/mem_entry_impl.h" | 15 #include "net/disk_cache/mem_entry_impl.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 using base::Time; | 18 using base::Time; |
| 18 | 19 |
| 19 extern volatile int g_cache_tests_received; | 20 extern volatile int g_cache_tests_received; |
| 20 extern volatile bool g_cache_tests_error; | 21 extern volatile bool g_cache_tests_error; |
| (...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 EXPECT_EQ(disk_cache::MemEntryImpl::kParentEntry, mem_entry->type()); | 874 EXPECT_EQ(disk_cache::MemEntryImpl::kParentEntry, mem_entry->type()); |
| 874 mem_entry->Close(); | 875 mem_entry->Close(); |
| 875 } | 876 } |
| 876 EXPECT_EQ(1, count); | 877 EXPECT_EQ(1, count); |
| 877 } | 878 } |
| 878 | 879 |
| 879 // Writes |buf_1| to offset and reads it back as |buf_2|. | 880 // Writes |buf_1| to offset and reads it back as |buf_2|. |
| 880 void VerifySparseIO(disk_cache::Entry* entry, int64 offset, | 881 void VerifySparseIO(disk_cache::Entry* entry, int64 offset, |
| 881 net::IOBuffer* buf_1, int size, bool async, | 882 net::IOBuffer* buf_1, int size, bool async, |
| 882 net::IOBuffer* buf_2) { | 883 net::IOBuffer* buf_2) { |
| 883 SimpleCallbackTest callback; | 884 TestCompletionCallback callback; |
| 884 SimpleCallbackTest* cb = async ? &callback : NULL; | 885 TestCompletionCallback* cb = async ? &callback : NULL; |
| 885 | 886 |
| 886 memset(buf_2->data(), 0, size); | 887 memset(buf_2->data(), 0, size); |
| 887 int ret = entry->ReadSparseData(offset, buf_2, size, cb); | 888 int ret = entry->ReadSparseData(offset, buf_2, size, cb); |
| 888 ret = callback.GetResult(ret); | 889 ret = callback.GetResult(ret); |
| 889 EXPECT_EQ(0, ret); | 890 EXPECT_EQ(0, ret); |
| 890 | 891 |
| 891 ret = entry->WriteSparseData(offset, buf_1, size, cb); | 892 ret = entry->WriteSparseData(offset, buf_1, size, cb); |
| 892 ret = callback.GetResult(ret); | 893 ret = callback.GetResult(ret); |
| 893 EXPECT_EQ(size, ret); | 894 EXPECT_EQ(size, ret); |
| 894 | 895 |
| 895 ret = entry->ReadSparseData(offset, buf_2, size, cb); | 896 ret = entry->ReadSparseData(offset, buf_2, size, cb); |
| 896 ret = callback.GetResult(ret); | 897 ret = callback.GetResult(ret); |
| 897 EXPECT_EQ(size, ret); | 898 EXPECT_EQ(size, ret); |
| 898 | 899 |
| 899 EXPECT_EQ(0, memcmp(buf_1->data(), buf_2->data(), size)); | 900 EXPECT_EQ(0, memcmp(buf_1->data(), buf_2->data(), size)); |
| 900 } | 901 } |
| 901 | 902 |
| 902 // Reads |size| bytes from |entry| at |offset| and verifies that they are the | 903 // Reads |size| bytes from |entry| at |offset| and verifies that they are the |
| 903 // same as the content of the provided |buffer|. | 904 // same as the content of the provided |buffer|. |
| 904 void VerifyContentSparseIO(disk_cache::Entry* entry, int64 offset, char* buffer, | 905 void VerifyContentSparseIO(disk_cache::Entry* entry, int64 offset, char* buffer, |
| 905 int size, bool async) { | 906 int size, bool async) { |
| 906 SimpleCallbackTest callback; | 907 TestCompletionCallback callback; |
| 907 SimpleCallbackTest* cb = async ? &callback : NULL; | 908 TestCompletionCallback* cb = async ? &callback : NULL; |
| 908 | 909 |
| 909 scoped_refptr<net::IOBuffer> buf_1 = new net::IOBuffer(size); | 910 scoped_refptr<net::IOBuffer> buf_1 = new net::IOBuffer(size); |
| 910 memset(buf_1->data(), 0, size); | 911 memset(buf_1->data(), 0, size); |
| 911 int ret = entry->ReadSparseData(offset, buf_1, size, cb); | 912 int ret = entry->ReadSparseData(offset, buf_1, size, cb); |
| 912 ret = callback.GetResult(ret); | 913 ret = callback.GetResult(ret); |
| 913 EXPECT_EQ(size, ret); | 914 EXPECT_EQ(size, ret); |
| 914 | 915 |
| 915 EXPECT_EQ(0, memcmp(buf_1->data(), buffer, size)); | 916 EXPECT_EQ(0, memcmp(buf_1->data(), buffer, size)); |
| 916 } | 917 } |
| 917 | 918 |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1347 TEST_F(DiskCacheEntryTest, CancelSparseIO) { | 1348 TEST_F(DiskCacheEntryTest, CancelSparseIO) { |
| 1348 InitCache(); | 1349 InitCache(); |
| 1349 std::string key("the first key"); | 1350 std::string key("the first key"); |
| 1350 disk_cache::Entry* entry; | 1351 disk_cache::Entry* entry; |
| 1351 ASSERT_TRUE(cache_->CreateEntry(key, &entry)); | 1352 ASSERT_TRUE(cache_->CreateEntry(key, &entry)); |
| 1352 | 1353 |
| 1353 const int kSize = 40 * 1024; | 1354 const int kSize = 40 * 1024; |
| 1354 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize); | 1355 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize); |
| 1355 CacheTestFillBuffer(buf->data(), kSize, false); | 1356 CacheTestFillBuffer(buf->data(), kSize, false); |
| 1356 | 1357 |
| 1357 SimpleCallbackTest cb1, cb2, cb3, cb4; | 1358 TestCompletionCallback cb1, cb2, cb3, cb4; |
| 1358 int64 offset = 0; | 1359 int64 offset = 0; |
| 1359 int tries = 0; | 1360 int tries = 0; |
| 1360 const int maxtries = 100; // Avoid hang on infinitely fast disks | 1361 const int maxtries = 100; // Avoid hang on infinitely fast disks |
| 1361 for (int ret = 0; ret != net::ERR_IO_PENDING; offset += kSize * 4) { | 1362 for (int ret = 0; ret != net::ERR_IO_PENDING; offset += kSize * 4) { |
| 1362 ret = entry->WriteSparseData(offset, buf, kSize, &cb1); | 1363 ret = entry->WriteSparseData(offset, buf, kSize, &cb1); |
| 1363 if (++tries > maxtries) { | 1364 if (++tries > maxtries) { |
| 1364 LOG(ERROR) << "Data writes never come back PENDING; skipping test"; | 1365 LOG(ERROR) << "Data writes never come back PENDING; skipping test"; |
| 1365 entry->Close(); | 1366 entry->Close(); |
| 1366 return; | 1367 return; |
| 1367 } | 1368 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1391 // Now see if we receive all notifications. | 1392 // Now see if we receive all notifications. |
| 1392 EXPECT_EQ(kSize, cb1.GetResult(net::ERR_IO_PENDING)); | 1393 EXPECT_EQ(kSize, cb1.GetResult(net::ERR_IO_PENDING)); |
| 1393 EXPECT_EQ(net::OK, cb2.GetResult(net::ERR_IO_PENDING)); | 1394 EXPECT_EQ(net::OK, cb2.GetResult(net::ERR_IO_PENDING)); |
| 1394 EXPECT_EQ(net::OK, cb3.GetResult(net::ERR_IO_PENDING)); | 1395 EXPECT_EQ(net::OK, cb3.GetResult(net::ERR_IO_PENDING)); |
| 1395 EXPECT_EQ(net::OK, cb4.GetResult(net::ERR_IO_PENDING)); | 1396 EXPECT_EQ(net::OK, cb4.GetResult(net::ERR_IO_PENDING)); |
| 1396 | 1397 |
| 1397 EXPECT_EQ(kSize, entry->GetAvailableRange(offset, kSize, &offset)); | 1398 EXPECT_EQ(kSize, entry->GetAvailableRange(offset, kSize, &offset)); |
| 1398 EXPECT_EQ(net::OK, entry->ReadyForSparseIO(&cb2)); | 1399 EXPECT_EQ(net::OK, entry->ReadyForSparseIO(&cb2)); |
| 1399 entry->Close(); | 1400 entry->Close(); |
| 1400 } | 1401 } |
| OLD | NEW |