Chromium Code Reviews| Index: content/browser/cache_storage/cache_storage_cache_unittest.cc |
| diff --git a/content/browser/cache_storage/cache_storage_cache_unittest.cc b/content/browser/cache_storage/cache_storage_cache_unittest.cc |
| index 5578d3e70b8df265aa1d07b84326afe126599216..5cba505bbe6d0cd620a8bbe95cd8c35938fceabd 100644 |
| --- a/content/browser/cache_storage/cache_storage_cache_unittest.cc |
| +++ b/content/browser/cache_storage/cache_storage_cache_unittest.cc |
| @@ -18,6 +18,7 @@ |
| #include "content/public/common/referrer.h" |
| #include "content/public/test/test_browser_context.h" |
| #include "content/public/test/test_browser_thread_bundle.h" |
| +#include "net/base/test_completion_callback.h" |
| #include "net/url_request/url_request_context.h" |
| #include "net/url_request/url_request_context_getter.h" |
| #include "net/url_request/url_request_job_factory_impl.h" |
| @@ -375,10 +376,32 @@ class CacheStorageCacheTest : public testing::Test { |
| } |
| void CopyBody(storage::BlobDataHandle* blob_handle, std::string* output) { |
| + *output = std::string(); |
| scoped_ptr<storage::BlobDataSnapshot> data = blob_handle->CreateSnapshot(); |
| const auto& items = data->items(); |
| for (const auto& item : items) { |
| - output->append(item->bytes(), item->GetLength()); |
| + switch (item->type()) { |
| + case storage::DataElement::TYPE_BYTES: { |
| + output->append(item->bytes(), item->GetLength()); |
| + } break; |
| + case storage::DataElement::TYPE_DISK_CACHE_ENTRY: { |
| + EXPECT_EQ(storage::DataElement::TYPE_DISK_CACHE_ENTRY, item->type()); |
|
jkarlin
2015/05/29 14:59:41
This seems redundant with the case.
gavinp
2015/05/29 18:06:07
Done.
|
| + disk_cache::Entry* entry = item->disk_cache_entry().get(); |
| + const int BODY_STREAM_INDEX = 1; |
|
jkarlin
2015/05/29 14:59:41
You can get the index from item->disk_cache_entry(
gavinp
2015/05/29 18:06:07
Done.
|
| + const int32 body_size = entry->GetDataSize(BODY_STREAM_INDEX); |
| + |
| + scoped_refptr<net::IOBuffer> io_buffer = new net::IOBuffer(body_size); |
| + net::TestCompletionCallback callback; |
| + int rv = entry->ReadData(BODY_STREAM_INDEX, 0, io_buffer.get(), |
| + body_size, callback.callback()); |
| + if (rv == net::ERR_IO_PENDING) |
| + rv = callback.WaitForResult(); |
| + EXPECT_EQ(body_size, rv); |
| + if (rv > 0) |
| + output->append(io_buffer->data(), rv); |
| + } break; |
| + default: { ADD_FAILURE() << "invalid response blob type"; } break; |
| + } |
| } |
| } |