Index: content/browser/fileapi/blob_url_request_job_unittest.cc |
diff --git a/content/browser/fileapi/blob_url_request_job_unittest.cc b/content/browser/fileapi/blob_url_request_job_unittest.cc |
index dd1ad1a6ac60b3d2dfbb907d9f3566e0bf2021a2..f40fbd34cae7f827c3c4422fe49cd03e93273bed 100644 |
--- a/content/browser/fileapi/blob_url_request_job_unittest.cc |
+++ b/content/browser/fileapi/blob_url_request_job_unittest.cc |
@@ -12,6 +12,7 @@ |
#include "base/numerics/safe_conversions.h" |
#include "base/run_loop.h" |
#include "base/time/time.h" |
+#include "content/browser/fileapi/blob_url_request_job_unittest.h" |
#include "content/public/test/async_file_test_helper.h" |
#include "content/public/test/test_file_system_context.h" |
#include "net/base/io_buffer.h" |
@@ -52,93 +53,80 @@ const fileapi::FileSystemType kFileSystemType = |
} // namespace |
-class BlobURLRequestJobTest : public testing::Test { |
- public: |
- |
- // Test Harness ------------------------------------------------------------- |
- // TODO(jianli): share this test harness with AppCacheURLRequestJobTest |
- |
- class MockURLRequestDelegate : public net::URLRequest::Delegate { |
- public: |
- MockURLRequestDelegate() |
- : received_data_(new net::IOBuffer(kBufferSize)) {} |
- |
- virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE { |
- if (request->status().is_success()) { |
- EXPECT_TRUE(request->response_headers()); |
- ReadSome(request); |
- } else { |
- RequestComplete(); |
- } |
- } |
+MockURLRequestDelegate::MockURLRequestDelegate() |
+ : received_data_(new net::IOBuffer(kBufferSize)) { |
+} |
- virtual void OnReadCompleted(net::URLRequest* request, |
- int bytes_read) OVERRIDE { |
- if (bytes_read > 0) |
- ReceiveData(request, bytes_read); |
- else |
- RequestComplete(); |
- } |
+MockURLRequestDelegate::~MockURLRequestDelegate() { |
+} |
- const std::string& response_data() const { return response_data_; } |
+void MockURLRequestDelegate::OnResponseStarted(net::URLRequest* request) { |
+ if (request->status().is_success()) { |
+ EXPECT_TRUE(request->response_headers()); |
+ ReadSome(request); |
+ } else { |
+ RequestComplete(); |
+ } |
+} |
- private: |
- void ReadSome(net::URLRequest* request) { |
- if (!request->is_pending()) { |
- RequestComplete(); |
- return; |
- } |
+void MockURLRequestDelegate::OnReadCompleted(net::URLRequest* request, |
+ int bytes_read) { |
+ if (bytes_read > 0) |
+ ReceiveData(request, bytes_read); |
+ else |
+ RequestComplete(); |
+} |
- int bytes_read = 0; |
- if (!request->Read(received_data_.get(), kBufferSize, &bytes_read)) { |
- if (!request->status().is_io_pending()) { |
- RequestComplete(); |
- } |
- return; |
- } |
+void MockURLRequestDelegate::ReadSome(net::URLRequest* request) { |
+ if (!request->is_pending()) { |
+ RequestComplete(); |
+ return; |
+ } |
- ReceiveData(request, bytes_read); |
+ int bytes_read = 0; |
+ if (!request->Read(received_data_.get(), kBufferSize, &bytes_read)) { |
+ if (!request->status().is_io_pending()) { |
+ RequestComplete(); |
} |
+ return; |
+ } |
- void ReceiveData(net::URLRequest* request, int bytes_read) { |
- if (bytes_read) { |
- response_data_.append(received_data_->data(), |
- static_cast<size_t>(bytes_read)); |
- ReadSome(request); |
- } else { |
- RequestComplete(); |
- } |
- } |
+ ReceiveData(request, bytes_read); |
+} |
- void RequestComplete() { |
- base::MessageLoop::current()->Quit(); |
- } |
+void MockURLRequestDelegate::ReceiveData(net::URLRequest* request, |
+ int bytes_read) { |
+ if (bytes_read) { |
+ response_data_.append(received_data_->data(), |
+ static_cast<size_t>(bytes_read)); |
+ ReadSome(request); |
+ } else { |
+ RequestComplete(); |
+ } |
+} |
- scoped_refptr<net::IOBuffer> received_data_; |
- std::string response_data_; |
- }; |
- |
- // A simple ProtocolHandler implementation to create BlobURLRequestJob. |
- class MockProtocolHandler : |
- public net::URLRequestJobFactory::ProtocolHandler { |
- public: |
- MockProtocolHandler(BlobURLRequestJobTest* test) : test_(test) {} |
- |
- // net::URLRequestJobFactory::ProtocolHandler override. |
- virtual net::URLRequestJob* MaybeCreateJob( |
- net::URLRequest* request, |
- net::NetworkDelegate* network_delegate) const OVERRIDE { |
- return new BlobURLRequestJob(request, |
- network_delegate, |
- test_->blob_data_.get(), |
- test_->file_system_context_.get(), |
- base::MessageLoopProxy::current().get()); |
- } |
+void MockURLRequestDelegate::RequestComplete() { |
+ base::MessageLoop::current()->Quit(); |
+} |
- private: |
- BlobURLRequestJobTest* test_; |
- }; |
+MockBlobProtocolHandler::MockBlobProtocolHandler( |
+ webkit_blob::BlobData* blob_data, |
+ fileapi::FileSystemContext* file_system_context) |
+ : blob_data_(blob_data), file_system_context_(file_system_context) { |
+} |
+ |
+net::URLRequestJob* MockBlobProtocolHandler::MaybeCreateJob( |
+ net::URLRequest* request, |
+ net::NetworkDelegate* network_delegate) const { |
+ return new BlobURLRequestJob(request, |
+ network_delegate, |
+ blob_data_, |
+ file_system_context_, |
+ base::MessageLoopProxy::current().get()); |
+} |
+class BlobURLRequestJobTest : public testing::Test { |
+ public: |
BlobURLRequestJobTest() |
: blob_data_(new BlobData()), |
expected_status_code_(0) {} |
@@ -162,8 +150,12 @@ class BlobURLRequestJobTest : public testing::Test { |
base::GetFileInfo(temp_file2_, &file_info2); |
temp_file_modification_time2_ = file_info2.last_modified; |
- url_request_job_factory_.SetProtocolHandler("blob", |
- new MockProtocolHandler(this)); |
+ file_system_context_ = |
+ CreateFileSystemContextForTesting(NULL, temp_dir_.path()); |
+ url_request_job_factory_.SetProtocolHandler( |
+ "blob", |
+ new MockBlobProtocolHandler(blob_data_.get(), |
+ file_system_context_.get())); |
url_request_context_.set_job_factory(&url_request_job_factory_); |
} |
@@ -172,9 +164,6 @@ class BlobURLRequestJobTest : public testing::Test { |
void SetUpFileSystem() { |
// Prepare file system. |
- file_system_context_ = CreateFileSystemContextForTesting( |
- NULL, temp_dir_.path()); |
- |
file_system_context_->OpenFileSystem( |
GURL(kFileSystemURLOrigin), |
kFileSystemType, |