Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: content/browser/cache_storage/cache_storage_cache_unittest.cc

Issue 1108083002: Create blobs from Disk Cache entries. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased to upstream CL, review this upload Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 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.
389 disk_cache::Entry* entry = item->disk_cache_entry().get();
390 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.
391 const int32 body_size = entry->GetDataSize(BODY_STREAM_INDEX);
392
393 scoped_refptr<net::IOBuffer> io_buffer = new net::IOBuffer(body_size);
394 net::TestCompletionCallback callback;
395 int rv = entry->ReadData(BODY_STREAM_INDEX, 0, io_buffer.get(),
396 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 default: { ADD_FAILURE() << "invalid response blob type"; } break;
404 }
382 } 405 }
383 } 406 }
384 407
385 bool VerifyKeys(const std::vector<std::string>& expected_keys) { 408 bool VerifyKeys(const std::vector<std::string>& expected_keys) {
386 if (expected_keys.size() != callback_strings_.size()) 409 if (expected_keys.size() != callback_strings_.size())
387 return false; 410 return false;
388 411
389 std::set<std::string> found_set; 412 std::set<std::string> found_set;
390 for (int i = 0, max = callback_strings_.size(); i < max; ++i) 413 for (int i = 0, max = callback_strings_.size(); i < max; ++i)
391 found_set.insert(callback_strings_[i]); 414 found_set.insert(callback_strings_[i]);
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 EXPECT_EQ(1, sequence_out); 885 EXPECT_EQ(1, sequence_out);
863 close_loop2->Run(); 886 close_loop2->Run();
864 EXPECT_EQ(2, sequence_out); 887 EXPECT_EQ(2, sequence_out);
865 } 888 }
866 889
867 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest, 890 INSTANTIATE_TEST_CASE_P(CacheStorageCacheTest,
868 CacheStorageCacheTestP, 891 CacheStorageCacheTestP,
869 ::testing::Values(false, true)); 892 ::testing::Values(false, true));
870 893
871 } // namespace content 894 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698