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/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.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 "content/browser/fileapi/chrome_blob_storage_context.h" | 12 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
13 #include "content/browser/fileapi/mock_url_request_delegate.h" | 13 #include "content/browser/fileapi/mock_url_request_delegate.h" |
14 #include "content/browser/quota/mock_quota_manager_proxy.h" | 14 #include "content/browser/quota/mock_quota_manager_proxy.h" |
15 #include "content/common/cache_storage/cache_storage_types.h" | 15 #include "content/common/cache_storage/cache_storage_types.h" |
16 #include "content/common/service_worker/service_worker_types.h" | 16 #include "content/common/service_worker/service_worker_types.h" |
17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/common/referrer.h" | 18 #include "content/public/common/referrer.h" |
19 #include "content/public/test/test_browser_context.h" | 19 #include "content/public/test/test_browser_context.h" |
20 #include "content/public/test/test_browser_thread_bundle.h" | 20 #include "content/public/test/test_browser_thread_bundle.h" |
| 21 #include "net/base/test_completion_callback.h" |
21 #include "net/url_request/url_request_context.h" | 22 #include "net/url_request/url_request_context.h" |
22 #include "net/url_request/url_request_context_getter.h" | 23 #include "net/url_request/url_request_context_getter.h" |
23 #include "net/url_request/url_request_job_factory_impl.h" | 24 #include "net/url_request/url_request_job_factory_impl.h" |
24 #include "storage/browser/blob/blob_data_builder.h" | 25 #include "storage/browser/blob/blob_data_builder.h" |
25 #include "storage/browser/blob/blob_data_handle.h" | 26 #include "storage/browser/blob/blob_data_handle.h" |
26 #include "storage/browser/blob/blob_data_snapshot.h" | 27 #include "storage/browser/blob/blob_data_snapshot.h" |
27 #include "storage/browser/blob/blob_storage_context.h" | 28 #include "storage/browser/blob/blob_storage_context.h" |
28 #include "storage/browser/blob/blob_url_request_job_factory.h" | 29 #include "storage/browser/blob/blob_url_request_job_factory.h" |
29 #include "storage/browser/quota/quota_manager_proxy.h" | 30 #include "storage/browser/quota/quota_manager_proxy.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 337 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->GetLength()); | 383 switch (item->type()) { |
| 384 case storage::DataElement::TYPE_BYTES: { |
| 385 output->append(item->bytes(), item->GetLength()); |
| 386 } break; |
| 387 case storage::DataElement::TYPE_DISK_CACHE_ENTRY: { |
| 388 disk_cache::Entry* entry = item->disk_cache_entry().get(); |
| 389 const int32 body_size = entry->GetDataSize( |
| 390 item->disk_cache_entry()->disk_cache_stream_index()); |
| 391 |
| 392 scoped_refptr<net::IOBuffer> io_buffer = new net::IOBuffer(body_size); |
| 393 net::TestCompletionCallback callback; |
| 394 int rv = entry->ReadData(BODY_STREAM_INDEX, 0, io_buffer.get(), |
| 395 body_size, callback.callback()); |
| 396 if (rv == net::ERR_IO_PENDING) |
| 397 rv = callback.WaitForResult(); |
| 398 EXPECT_EQ(body_size, rv); |
| 399 if (rv > 0) |
| 400 output->append(io_buffer->data(), rv); |
| 401 } break; |
| 402 default: { ADD_FAILURE() << "invalid response blob type"; } break; |
| 403 } |
382 } | 404 } |
383 } | 405 } |
384 | 406 |
385 bool VerifyKeys(const std::vector<std::string>& expected_keys) { | 407 bool VerifyKeys(const std::vector<std::string>& expected_keys) { |
386 if (expected_keys.size() != callback_strings_.size()) | 408 if (expected_keys.size() != callback_strings_.size()) |
387 return false; | 409 return false; |
388 | 410 |
389 std::set<std::string> found_set; | 411 std::set<std::string> found_set; |
390 for (int i = 0, max = callback_strings_.size(); i < max; ++i) | 412 for (int i = 0, max = callback_strings_.size(); i < max; ++i) |
391 found_set.insert(callback_strings_[i]); | 413 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); | 884 EXPECT_EQ(1, sequence_out); |
863 close_loop2->Run(); | 885 close_loop2->Run(); |
864 EXPECT_EQ(2, sequence_out); | 886 EXPECT_EQ(2, sequence_out); |
865 } | 887 } |
866 | 888 |
867 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, | 889 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, |
868 CacheStorageCacheTestP, | 890 CacheStorageCacheTestP, |
869 ::testing::Values(false, true)); | 891 ::testing::Values(false, true)); |
870 | 892 |
871 } // namespace content | 893 } // namespace content |
OLD | NEW |