diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-16 05:16:23 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-16 05:16:23 +0000 |
commit | 169adebb59774f88757a940621998440c590336b (patch) | |
tree | 7dda8ad06b08912556d30eac97058b2ad58e9d83 /webkit/blob | |
parent | b1b800c69645b72c13df44a5b770d5b295b194fb (diff) | |
download | chromium_src-169adebb59774f88757a940621998440c590336b.zip chromium_src-169adebb59774f88757a940621998440c590336b.tar.gz chromium_src-169adebb59774f88757a940621998440c590336b.tar.bz2 |
Implement CannedSyncableFileSystem.Write for write testing
Also factor out MockBlobURLRequestContext class so that we can easily
test writing with blob urls.
BUG=148897
TEST=LocalFileChangeTrackerTest.*
TBR=jam@chromium.org
Review URL: https://codereview.chromium.org/11146015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162078 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/blob')
-rw-r--r-- | webkit/blob/mock_blob_url_request_context.cc | 68 | ||||
-rw-r--r-- | webkit/blob/mock_blob_url_request_context.h | 48 |
2 files changed, 116 insertions, 0 deletions
diff --git a/webkit/blob/mock_blob_url_request_context.cc b/webkit/blob/mock_blob_url_request_context.cc new file mode 100644 index 0000000..8cc06bc --- /dev/null +++ b/webkit/blob/mock_blob_url_request_context.cc @@ -0,0 +1,68 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/blob/mock_blob_url_request_context.h" + +#include "webkit/blob/blob_data.h" +#include "webkit/blob/blob_storage_controller.h" +#include "webkit/blob/blob_url_request_job.h" + +namespace webkit_blob { + +namespace { + +class MockBlobProtocolHandler + : public net::URLRequestJobFactory::ProtocolHandler { + public: + explicit MockBlobProtocolHandler( + BlobStorageController* blob_storage_controller) + : blob_storage_controller_(blob_storage_controller) {} + + virtual ~MockBlobProtocolHandler() {} + + virtual net::URLRequestJob* MaybeCreateJob( + net::URLRequest* request, + net::NetworkDelegate* network_delegate) const OVERRIDE { + return new BlobURLRequestJob( + request, + network_delegate, + blob_storage_controller_->GetBlobDataFromUrl(request->url()), + base::MessageLoopProxy::current()); + } + + private: + webkit_blob::BlobStorageController* const blob_storage_controller_; + + DISALLOW_COPY_AND_ASSIGN(MockBlobProtocolHandler); +}; + +} // namespace + +MockBlobURLRequestContext::MockBlobURLRequestContext() + : blob_storage_controller_(new BlobStorageController) { + // Job factory owns the protocol handler. + job_factory_.SetProtocolHandler( + "blob", new MockBlobProtocolHandler(blob_storage_controller_.get())); + set_job_factory(&job_factory_); +} + +MockBlobURLRequestContext::~MockBlobURLRequestContext() {} + +ScopedTextBlob::ScopedTextBlob( + const MockBlobURLRequestContext& request_context, + const GURL& blob_url, + const std::string& data) + : blob_url_(blob_url), + blob_storage_controller_(request_context.blob_storage_controller()) { + DCHECK(blob_storage_controller_); + scoped_refptr<BlobData> blob_data(new BlobData()); + blob_data->AppendData(data); + blob_storage_controller_->AddFinishedBlob(blob_url_, blob_data); +} + +ScopedTextBlob::~ScopedTextBlob() { + blob_storage_controller_->RemoveBlob(blob_url_); +} + +} // namespace webkit_blob diff --git a/webkit/blob/mock_blob_url_request_context.h b/webkit/blob/mock_blob_url_request_context.h new file mode 100644 index 0000000..9190db9 --- /dev/null +++ b/webkit/blob/mock_blob_url_request_context.h @@ -0,0 +1,48 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef WEBKIT_BLOB_MOCK_BLOB_URL_REQUEST_CONTEXT_H_ +#define WEBKIT_BLOB_MOCK_BLOB_URL_REQUEST_CONTEXT_H_ + +#include "net/url_request/url_request_context.h" +#include "net/url_request/url_request_job.h" +#include "net/url_request/url_request_job_factory_impl.h" + +namespace webkit_blob { + +class BlobStorageController; + +class MockBlobURLRequestContext : public net::URLRequestContext { + public: + MockBlobURLRequestContext(); + virtual ~MockBlobURLRequestContext(); + + BlobStorageController* blob_storage_controller() const { + return blob_storage_controller_.get(); + } + + private: + net::URLRequestJobFactoryImpl job_factory_; + scoped_ptr<BlobStorageController> blob_storage_controller_; + + DISALLOW_COPY_AND_ASSIGN(MockBlobURLRequestContext); +}; + +class ScopedTextBlob { + public: + ScopedTextBlob(const MockBlobURLRequestContext& request_context, + const GURL& blob_url, + const std::string& data); + ~ScopedTextBlob(); + + private: + const GURL blob_url_; + BlobStorageController* blob_storage_controller_; + + DISALLOW_COPY_AND_ASSIGN(ScopedTextBlob); +}; + +} // namespace webkit_blob + +#endif // WEBKIT_BLOB_MOCK_BLOB_URL_REQUEST_CONTEXT_H_ |