OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/cache_storage/cache_storage_cache.h" | 5 #include "content/browser/cache_storage/cache_storage_cache.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
13 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 13 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
14 #include "content/browser/fileapi/mock_url_request_delegate.h" | 14 #include "content/browser/fileapi/mock_url_request_delegate.h" |
15 #include "content/browser/quota/mock_quota_manager_proxy.h" | 15 #include "content/browser/quota/mock_quota_manager_proxy.h" |
16 #include "content/common/cache_storage/cache_storage_types.h" | 16 #include "content/common/cache_storage/cache_storage_types.h" |
17 #include "content/common/service_worker/service_worker_types.h" | 17 #include "content/common/service_worker/service_worker_types.h" |
18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/common/referrer.h" | 19 #include "content/public/common/referrer.h" |
20 #include "content/public/test/test_browser_context.h" | 20 #include "content/public/test/test_browser_context.h" |
21 #include "content/public/test/test_browser_thread_bundle.h" | 21 #include "content/public/test/test_browser_thread_bundle.h" |
| 22 #include "net/base/test_completion_callback.h" |
22 #include "net/url_request/url_request_context.h" | 23 #include "net/url_request/url_request_context.h" |
23 #include "net/url_request/url_request_context_getter.h" | 24 #include "net/url_request/url_request_context_getter.h" |
24 #include "net/url_request/url_request_job_factory_impl.h" | 25 #include "net/url_request/url_request_job_factory_impl.h" |
25 #include "storage/browser/blob/blob_data_builder.h" | 26 #include "storage/browser/blob/blob_data_builder.h" |
26 #include "storage/browser/blob/blob_data_handle.h" | 27 #include "storage/browser/blob/blob_data_handle.h" |
27 #include "storage/browser/blob/blob_data_snapshot.h" | 28 #include "storage/browser/blob/blob_data_snapshot.h" |
28 #include "storage/browser/blob/blob_storage_context.h" | 29 #include "storage/browser/blob/blob_storage_context.h" |
29 #include "storage/browser/blob/blob_url_request_job_factory.h" | 30 #include "storage/browser/blob/blob_url_request_job_factory.h" |
30 #include "storage/browser/quota/quota_manager_proxy.h" | 31 #include "storage/browser/quota/quota_manager_proxy.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 } | 369 } |
369 | 370 |
370 void CloseCallback(base::RunLoop* run_loop) { | 371 void CloseCallback(base::RunLoop* run_loop) { |
371 EXPECT_FALSE(callback_closed_); | 372 EXPECT_FALSE(callback_closed_); |
372 callback_closed_ = true; | 373 callback_closed_ = true; |
373 if (run_loop) | 374 if (run_loop) |
374 run_loop->Quit(); | 375 run_loop->Quit(); |
375 } | 376 } |
376 | 377 |
377 void CopyBody(storage::BlobDataHandle* blob_handle, std::string* output) { | 378 void CopyBody(storage::BlobDataHandle* blob_handle, std::string* output) { |
| 379 *output = std::string(); |
378 scoped_ptr<storage::BlobDataSnapshot> data = blob_handle->CreateSnapshot(); | 380 scoped_ptr<storage::BlobDataSnapshot> data = blob_handle->CreateSnapshot(); |
379 const auto& items = data->items(); | 381 const auto& items = data->items(); |
380 for (const auto& item : items) { | 382 for (const auto& item : items) { |
381 output->append(item->bytes(), item->length()); | 383 switch (item->type()) { |
| 384 case storage::DataElement::TYPE_BYTES: { |
| 385 output->append(item->bytes(), item->length()); |
| 386 break; |
| 387 } |
| 388 case storage::DataElement::TYPE_DISK_CACHE_ENTRY: { |
| 389 disk_cache::Entry* entry = item->disk_cache_entry(); |
| 390 int32 body_size = entry->GetDataSize(item->disk_cache_stream_index()); |
| 391 |
| 392 scoped_refptr<net::IOBuffer> io_buffer = new net::IOBuffer(body_size); |
| 393 net::TestCompletionCallback callback; |
| 394 int rv = |
| 395 entry->ReadData(item->disk_cache_stream_index(), 0, |
| 396 io_buffer.get(), body_size, callback.callback()); |
| 397 if (rv == net::ERR_IO_PENDING) |
| 398 rv = callback.WaitForResult(); |
| 399 EXPECT_EQ(body_size, rv); |
| 400 if (rv > 0) |
| 401 output->append(io_buffer->data(), rv); |
| 402 break; |
| 403 } |
| 404 default: { ADD_FAILURE() << "invalid response blob type"; } break; |
| 405 } |
382 } | 406 } |
383 } | 407 } |
384 | 408 |
385 bool VerifyKeys(const std::vector<std::string>& expected_keys) { | 409 bool VerifyKeys(const std::vector<std::string>& expected_keys) { |
386 if (expected_keys.size() != callback_strings_.size()) | 410 if (expected_keys.size() != callback_strings_.size()) |
387 return false; | 411 return false; |
388 | 412 |
389 std::set<std::string> found_set; | 413 std::set<std::string> found_set; |
390 for (int i = 0, max = callback_strings_.size(); i < max; ++i) | 414 for (int i = 0, max = callback_strings_.size(); i < max; ++i) |
391 found_set.insert(callback_strings_[i]); | 415 found_set.insert(callback_strings_[i]); |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 EXPECT_EQ(1, sequence_out); | 886 EXPECT_EQ(1, sequence_out); |
863 close_loop2->Run(); | 887 close_loop2->Run(); |
864 EXPECT_EQ(2, sequence_out); | 888 EXPECT_EQ(2, sequence_out); |
865 } | 889 } |
866 | 890 |
867 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, | 891 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, |
868 CacheStorageCacheTestP, | 892 CacheStorageCacheTestP, |
869 ::testing::Values(false, true)); | 893 ::testing::Values(false, true)); |
870 | 894 |
871 } // namespace content | 895 } // namespace content |
OLD | NEW |