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.
4
5#include "content/public/test/mock_blob_url_request_context.h"
6
7#include "storage/browser/blob/blob_storage_context.h"
8#include "storage/browser/blob/blob_url_request_job.h"
9#include "storage/browser/blob/blob_url_request_job_factory.h"
10#include "storage/common/blob/blob_data.h"
11
12
13namespace content {
14
15MockBlobURLRequestContext::MockBlobURLRequestContext(
16    storage::FileSystemContext* file_system_context)
17    : blob_storage_context_(new storage::BlobStorageContext) {
18  // Job factory owns the protocol handler.
19  job_factory_.SetProtocolHandler(
20      "blob",
21      new storage::BlobProtocolHandler(blob_storage_context_.get(),
22                                       file_system_context,
23                                       base::MessageLoopProxy::current()));
24  set_job_factory(&job_factory_);
25}
26
27MockBlobURLRequestContext::~MockBlobURLRequestContext() {
28  AssertNoURLRequests();
29}
30
31ScopedTextBlob::ScopedTextBlob(
32    const MockBlobURLRequestContext& request_context,
33    const std::string& blob_id,
34    const std::string& data)
35    : blob_id_(blob_id),
36      context_(request_context.blob_storage_context()) {
37  DCHECK(context_);
38  scoped_refptr<storage::BlobData> blob_data(new storage::BlobData(blob_id_));
39  if (!data.empty())
40    blob_data->AppendData(data);
41  handle_ = context_->AddFinishedBlob(blob_data.get());
42}
43
44ScopedTextBlob::~ScopedTextBlob() {
45}
46
47scoped_ptr<storage::BlobDataHandle> ScopedTextBlob::GetBlobDataHandle() {
48  return context_->GetBlobDataFromUUID(blob_id_);
49}
50
51}  // namespace content
52