Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / public / test / mock_blob_url_request_context.cc
blobf0cd546199109723b03927cdf2995552d00c0208
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
3 // found in the LICENSE file.
5 #include "content/public/test/mock_blob_url_request_context.h"
7 #include "storage/browser/blob/blob_data_builder.h"
8 #include "storage/browser/blob/blob_storage_context.h"
9 #include "storage/browser/blob/blob_url_request_job.h"
10 #include "storage/browser/blob/blob_url_request_job_factory.h"
12 namespace content {
14 MockBlobURLRequestContext::MockBlobURLRequestContext(
15 storage::FileSystemContext* file_system_context)
16 : blob_storage_context_(new storage::BlobStorageContext) {
17 // Job factory owns the protocol handler.
18 job_factory_.SetProtocolHandler(
19 "blob",
20 new storage::BlobProtocolHandler(blob_storage_context_.get(),
21 file_system_context,
22 base::MessageLoopProxy::current()));
23 set_job_factory(&job_factory_);
26 MockBlobURLRequestContext::~MockBlobURLRequestContext() {
27 AssertNoURLRequests();
30 ScopedTextBlob::ScopedTextBlob(
31 const MockBlobURLRequestContext& request_context,
32 const std::string& blob_id,
33 const std::string& data)
34 : blob_id_(blob_id),
35 context_(request_context.blob_storage_context()) {
36 DCHECK(context_);
37 storage::BlobDataBuilder blob_builder(blob_id_);
38 if (!data.empty())
39 blob_builder.AppendData(data);
40 handle_ = context_->AddFinishedBlob(&blob_builder);
43 ScopedTextBlob::~ScopedTextBlob() {
46 scoped_ptr<storage::BlobDataHandle> ScopedTextBlob::GetBlobDataHandle() {
47 return context_->GetBlobDataFromUUID(blob_id_);
50 } // namespace content