summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
Diffstat (limited to 'webkit')
-rw-r--r--webkit/blob/mock_blob_url_request_context.cc68
-rw-r--r--webkit/blob/mock_blob_url_request_context.h48
-rw-r--r--webkit/fileapi/local_file_system_operation_write_unittest.cc136
-rw-r--r--webkit/fileapi/syncable/canned_syncable_file_system.cc124
-rw-r--r--webkit/fileapi/syncable/canned_syncable_file_system.h13
-rw-r--r--webkit/fileapi/syncable/local_file_change_tracker_unittest.cc50
-rw-r--r--webkit/fileapi/syncable/local_file_sync_context_unittest.cc3
7 files changed, 277 insertions, 165 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_
diff --git a/webkit/fileapi/local_file_system_operation_write_unittest.cc b/webkit/fileapi/local_file_system_operation_write_unittest.cc
index afd2525..96de647 100644
--- a/webkit/fileapi/local_file_system_operation_write_unittest.cc
+++ b/webkit/fileapi/local_file_system_operation_write_unittest.cc
@@ -18,6 +18,7 @@
#include "webkit/blob/blob_data.h"
#include "webkit/blob/blob_storage_controller.h"
#include "webkit/blob/blob_url_request_job.h"
+#include "webkit/blob/mock_blob_url_request_context.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_file_util.h"
#include "webkit/fileapi/file_system_util.h"
@@ -28,6 +29,8 @@
#include "webkit/quota/quota_manager.h"
using quota::QuotaManager;
+using webkit_blob::MockBlobURLRequestContext;
+using webkit_blob::ScopedTextBlob;
namespace fileapi {
@@ -157,6 +160,8 @@ class LocalFileSystemOperationWriteTest
int64 bytes_written_;
bool complete_;
+ MockBlobURLRequestContext url_request_context_;
+
DISALLOW_COPY_AND_ASSIGN(LocalFileSystemOperationWriteTest);
private:
@@ -164,57 +169,6 @@ class LocalFileSystemOperationWriteTest
ChangeObserverList change_observers_;
};
-namespace {
-
-class TestProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler {
- public:
- explicit TestProtocolHandler(
- webkit_blob::BlobStorageController* blob_storage_controller)
- : blob_storage_controller_(blob_storage_controller) {}
-
- virtual ~TestProtocolHandler() {}
-
- virtual net::URLRequestJob* MaybeCreateJob(
- net::URLRequest* request,
- net::NetworkDelegate* network_delegate) const OVERRIDE {
- return new webkit_blob::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(TestProtocolHandler);
-};
-
-class TestURLRequestContext : public net::URLRequestContext {
- public:
- TestURLRequestContext()
- : blob_storage_controller_(new webkit_blob::BlobStorageController) {
- // Job factory owns the protocol handler.
- job_factory_.SetProtocolHandler(
- "blob", new TestProtocolHandler(blob_storage_controller_.get()));
- set_job_factory(&job_factory_);
- }
-
- virtual ~TestURLRequestContext() {}
-
- webkit_blob::BlobStorageController* blob_storage_controller() const {
- return blob_storage_controller_.get();
- }
-
- private:
- net::URLRequestJobFactoryImpl job_factory_;
- scoped_ptr<webkit_blob::BlobStorageController> blob_storage_controller_;
-
- DISALLOW_COPY_AND_ASSIGN(TestURLRequestContext);
-};
-
-} // namespace (anonymous)
-
void LocalFileSystemOperationWriteTest::SetUp() {
ASSERT_TRUE(dir_.CreateUniqueTempDir());
FilePath base_dir = dir_.path().AppendASCII("filesystem");
@@ -243,20 +197,13 @@ LocalFileSystemOperation* LocalFileSystemOperationWriteTest::operation() {
}
TEST_F(LocalFileSystemOperationWriteTest, TestWriteSuccess) {
- GURL blob_url("blob:success");
- scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData());
- blob_data->AppendData("Hello, world!\n");
+ const GURL blob_url("blob:success");
+ ScopedTextBlob blob(url_request_context_, blob_url, "Hello, world!\n");
- TestURLRequestContext url_request_context;
- url_request_context.blob_storage_controller()->AddFinishedBlob(
- blob_url, blob_data);
-
- operation()->Write(&url_request_context, URLForPath(virtual_path_), blob_url,
+ operation()->Write(&url_request_context_, URLForPath(virtual_path_), blob_url,
0, RecordWriteCallback());
MessageLoop::current()->Run();
- url_request_context.blob_storage_controller()->RemoveBlob(blob_url);
-
EXPECT_EQ(14, bytes_written());
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(complete());
@@ -268,15 +215,14 @@ TEST_F(LocalFileSystemOperationWriteTest, TestWriteZero) {
GURL blob_url("blob:zero");
scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData());
- TestURLRequestContext url_request_context;
- url_request_context.blob_storage_controller()->AddFinishedBlob(
+ url_request_context_.blob_storage_controller()->AddFinishedBlob(
blob_url, blob_data);
- operation()->Write(&url_request_context, URLForPath(virtual_path_),
+ operation()->Write(&url_request_context_, URLForPath(virtual_path_),
blob_url, 0, RecordWriteCallback());
MessageLoop::current()->Run();
- url_request_context.blob_storage_controller()->RemoveBlob(blob_url);
+ url_request_context_.blob_storage_controller()->RemoveBlob(blob_url);
EXPECT_EQ(0, bytes_written());
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
@@ -286,9 +232,7 @@ TEST_F(LocalFileSystemOperationWriteTest, TestWriteZero) {
}
TEST_F(LocalFileSystemOperationWriteTest, TestWriteInvalidBlobUrl) {
- TestURLRequestContext url_request_context;
-
- operation()->Write(&url_request_context, URLForPath(virtual_path_),
+ operation()->Write(&url_request_context_, URLForPath(virtual_path_),
GURL("blob:invalid"), 0, RecordWriteCallback());
MessageLoop::current()->Run();
@@ -301,20 +245,13 @@ TEST_F(LocalFileSystemOperationWriteTest, TestWriteInvalidBlobUrl) {
TEST_F(LocalFileSystemOperationWriteTest, TestWriteInvalidFile) {
GURL blob_url("blob:writeinvalidfile");
- scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData());
- blob_data->AppendData("It\'ll not be written.");
-
- TestURLRequestContext url_request_context;
- url_request_context.blob_storage_controller()->AddFinishedBlob(
- blob_url, blob_data);
+ ScopedTextBlob blob(url_request_context_, blob_url, "It\'ll not be written.");
- operation()->Write(&url_request_context,
+ operation()->Write(&url_request_context_,
URLForPath(FilePath(FILE_PATH_LITERAL("nonexist"))),
blob_url, 0, RecordWriteCallback());
MessageLoop::current()->Run();
- url_request_context.blob_storage_controller()->RemoveBlob(blob_url);
-
EXPECT_EQ(0, bytes_written());
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
EXPECT_TRUE(complete());
@@ -330,19 +267,13 @@ TEST_F(LocalFileSystemOperationWriteTest, TestWriteDir) {
base::Bind(&AssertStatusEq, base::PLATFORM_FILE_OK));
GURL blob_url("blob:writedir");
- scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData());
- blob_data->AppendData("It\'ll not be written, too.");
-
- TestURLRequestContext url_request_context;
- url_request_context.blob_storage_controller()->AddFinishedBlob(
- blob_url, blob_data);
+ ScopedTextBlob blob(url_request_context_, blob_url,
+ "It\'ll not be written, too.");
- operation()->Write(&url_request_context, URLForPath(virtual_dir_path),
+ operation()->Write(&url_request_context_, URLForPath(virtual_dir_path),
blob_url, 0, RecordWriteCallback());
MessageLoop::current()->Run();
- url_request_context.blob_storage_controller()->RemoveBlob(blob_url);
-
EXPECT_EQ(0, bytes_written());
// TODO(kinuko): This error code is platform- or fileutil- dependent
// right now. Make it return PLATFORM_FILE_ERROR_NOT_A_FILE in every case.
@@ -356,20 +287,13 @@ TEST_F(LocalFileSystemOperationWriteTest, TestWriteDir) {
TEST_F(LocalFileSystemOperationWriteTest, TestWriteFailureByQuota) {
GURL blob_url("blob:success");
- scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData());
- blob_data->AppendData("Hello, world!\n");
-
- TestURLRequestContext url_request_context;
- url_request_context.blob_storage_controller()->AddFinishedBlob(
- blob_url, blob_data);
+ ScopedTextBlob blob(url_request_context_, blob_url, "Hello, world!\n");
quota_manager_->set_quota(10);
- operation()->Write(&url_request_context, URLForPath(virtual_path_), blob_url,
+ operation()->Write(&url_request_context_, URLForPath(virtual_path_), blob_url,
0, RecordWriteCallback());
MessageLoop::current()->Run();
- url_request_context.blob_storage_controller()->RemoveBlob(blob_url);
-
EXPECT_EQ(10, bytes_written());
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status());
EXPECT_TRUE(complete());
@@ -379,15 +303,10 @@ TEST_F(LocalFileSystemOperationWriteTest, TestWriteFailureByQuota) {
TEST_F(LocalFileSystemOperationWriteTest, TestImmediateCancelSuccessfulWrite) {
GURL blob_url("blob:success");
- scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData());
- blob_data->AppendData("Hello, world!\n");
-
- TestURLRequestContext url_request_context;
- url_request_context.blob_storage_controller()->AddFinishedBlob(
- blob_url, blob_data);
+ ScopedTextBlob blob(url_request_context_, blob_url, "Hello, world!\n");
FileSystemOperation* write_operation = operation();
- write_operation->Write(&url_request_context, URLForPath(virtual_path_),
+ write_operation->Write(&url_request_context_, URLForPath(virtual_path_),
blob_url, 0, RecordWriteCallback());
write_operation->Cancel(RecordCancelCallback());
// We use RunAllPendings() instead of Run() here, because we won't dispatch
@@ -395,8 +314,6 @@ TEST_F(LocalFileSystemOperationWriteTest, TestImmediateCancelSuccessfulWrite) {
// to run another write cycle.
MessageLoop::current()->RunAllPending();
- url_request_context.blob_storage_controller()->RemoveBlob(blob_url);
-
// Issued Cancel() before receiving any response from Write(),
// so nothing should have happen.
EXPECT_EQ(0, bytes_written());
@@ -409,15 +326,10 @@ TEST_F(LocalFileSystemOperationWriteTest, TestImmediateCancelSuccessfulWrite) {
TEST_F(LocalFileSystemOperationWriteTest, TestImmediateCancelFailingWrite) {
GURL blob_url("blob:writeinvalidfile");
- scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData());
- blob_data->AppendData("It\'ll not be written.");
-
- TestURLRequestContext url_request_context;
- url_request_context.blob_storage_controller()->AddFinishedBlob(
- blob_url, blob_data);
+ ScopedTextBlob blob(url_request_context_, blob_url, "It\'ll not be written.");
FileSystemOperation* write_operation = operation();
- write_operation->Write(&url_request_context,
+ write_operation->Write(&url_request_context_,
URLForPath(FilePath(FILE_PATH_LITERAL("nonexist"))),
blob_url, 0, RecordWriteCallback());
write_operation->Cancel(RecordCancelCallback());
@@ -426,8 +338,6 @@ TEST_F(LocalFileSystemOperationWriteTest, TestImmediateCancelFailingWrite) {
// to run another write cycle.
MessageLoop::current()->RunAllPending();
- url_request_context.blob_storage_controller()->RemoveBlob(blob_url);
-
// Issued Cancel() before receiving any response from Write(),
// so nothing should have happen.
EXPECT_EQ(0, bytes_written());
diff --git a/webkit/fileapi/syncable/canned_syncable_file_system.cc b/webkit/fileapi/syncable/canned_syncable_file_system.cc
index b6fab40..ff7992b 100644
--- a/webkit/fileapi/syncable/canned_syncable_file_system.cc
+++ b/webkit/fileapi/syncable/canned_syncable_file_system.cc
@@ -28,28 +28,28 @@ namespace fileapi {
namespace {
-typedef CannedSyncableFileSystem::StatusCallback StatusCallback;
-
void Empty() {}
void Quit() { MessageLoop::current()->Quit(); }
+template <typename R>
void AssignAndQuit(base::TaskRunner* original_task_runner,
- PlatformFileError* result_out,
- PlatformFileError result) {
+ R* result_out, R result) {
DCHECK(result_out);
*result_out = result;
original_task_runner->PostTask(FROM_HERE, base::Bind(&Quit));
}
-PlatformFileError RunOnThread(
+
+template <typename R>
+R RunOnThread(
base::SingleThreadTaskRunner* task_runner,
const tracked_objects::Location& location,
- const base::Callback<void(const StatusCallback& callback)>& task) {
- PlatformFileError result = base::PLATFORM_FILE_ERROR_FAILED;
+ const base::Callback<void(const base::Callback<void(R)>& callback)>& task) {
+ R result;
task_runner->PostTask(
location,
- base::Bind(task, base::Bind(&AssignAndQuit,
+ base::Bind(task, base::Bind(&AssignAndQuit<R>,
base::MessageLoopProxy::current(),
&result)));
MessageLoop::current()->Run();
@@ -69,6 +69,26 @@ void VerifySameTaskRunner(
base::Bind(&EnsureRunningOn, make_scoped_refptr(runner2)));
}
+class WriteHelper {
+ public:
+ WriteHelper() : bytes_written_(0) {}
+ ~WriteHelper() {}
+
+ void DidWrite(const base::Callback<void(int64)>& completion_callback,
+ PlatformFileError error, int64 bytes, bool complete) {
+ if (error == base::PLATFORM_FILE_OK) {
+ bytes_written_ += bytes;
+ if (!complete)
+ return;
+ }
+ completion_callback.Run(error == base::PLATFORM_FILE_OK
+ ? bytes_written_ : static_cast<int64>(error));
+ }
+
+ private:
+ int64 bytes_written_;
+};
+
} // namespace
CannedSyncableFileSystem::CannedSyncableFileSystem(
@@ -154,60 +174,77 @@ SyncStatusCode CannedSyncableFileSystem::MaybeInitializeFileSystemContext(
PlatformFileError CannedSyncableFileSystem::CreateDirectory(
const FileSystemURL& url) {
- return RunOnThread(io_task_runner_,
- FROM_HERE,
- base::Bind(&CannedSyncableFileSystem::DoCreateDirectory,
- base::Unretained(this), url));
+ return RunOnThread<PlatformFileError>(
+ io_task_runner_,
+ FROM_HERE,
+ base::Bind(&CannedSyncableFileSystem::DoCreateDirectory,
+ base::Unretained(this), url));
}
PlatformFileError CannedSyncableFileSystem::CreateFile(
const FileSystemURL& url) {
- return RunOnThread(io_task_runner_,
- FROM_HERE,
- base::Bind(&CannedSyncableFileSystem::DoCreateFile,
- base::Unretained(this), url));
+ return RunOnThread<PlatformFileError>(
+ io_task_runner_,
+ FROM_HERE,
+ base::Bind(&CannedSyncableFileSystem::DoCreateFile,
+ base::Unretained(this), url));
}
PlatformFileError CannedSyncableFileSystem::Copy(
const FileSystemURL& src_url, const FileSystemURL& dest_url) {
- return RunOnThread(io_task_runner_,
- FROM_HERE,
- base::Bind(&CannedSyncableFileSystem::DoCopy,
- base::Unretained(this), src_url, dest_url));
+ return RunOnThread<PlatformFileError>(
+ io_task_runner_,
+ FROM_HERE,
+ base::Bind(&CannedSyncableFileSystem::DoCopy,
+ base::Unretained(this), src_url, dest_url));
}
PlatformFileError CannedSyncableFileSystem::Move(
const FileSystemURL& src_url, const FileSystemURL& dest_url) {
- return RunOnThread(io_task_runner_,
- FROM_HERE,
- base::Bind(&CannedSyncableFileSystem::DoMove,
- base::Unretained(this), src_url, dest_url));
+ return RunOnThread<PlatformFileError>(
+ io_task_runner_,
+ FROM_HERE,
+ base::Bind(&CannedSyncableFileSystem::DoMove,
+ base::Unretained(this), src_url, dest_url));
}
PlatformFileError CannedSyncableFileSystem::TruncateFile(
const FileSystemURL& url, int64 size) {
- return RunOnThread(io_task_runner_,
- FROM_HERE,
- base::Bind(&CannedSyncableFileSystem::DoTruncateFile,
- base::Unretained(this), url, size));
+ return RunOnThread<PlatformFileError>(
+ io_task_runner_,
+ FROM_HERE,
+ base::Bind(&CannedSyncableFileSystem::DoTruncateFile,
+ base::Unretained(this), url, size));
}
PlatformFileError CannedSyncableFileSystem::Remove(
const FileSystemURL& url, bool recursive) {
- return RunOnThread(io_task_runner_,
- FROM_HERE,
- base::Bind(&CannedSyncableFileSystem::DoRemove,
- base::Unretained(this), url, recursive));
+ return RunOnThread<PlatformFileError>(
+ io_task_runner_,
+ FROM_HERE,
+ base::Bind(&CannedSyncableFileSystem::DoRemove,
+ base::Unretained(this), url, recursive));
+}
+
+int64 CannedSyncableFileSystem::Write(
+ net::URLRequestContext* url_request_context,
+ const FileSystemURL& url, const GURL& blob_url) {
+ return RunOnThread<int64>(
+ io_task_runner_,
+ FROM_HERE,
+ base::Bind(&CannedSyncableFileSystem::DoWrite,
+ base::Unretained(this), url_request_context, url, blob_url));
}
PlatformFileError CannedSyncableFileSystem::DeleteFileSystem() {
EXPECT_TRUE(is_filesystem_set_up_);
- return RunOnThread(io_task_runner_,
- FROM_HERE,
- base::Bind(&FileSystemContext::DeleteFileSystem,
- file_system_context_,
- test_helper_.origin(),
- test_helper_.type()));
+ return RunOnThread<PlatformFileError>(
+ io_task_runner_,
+ FROM_HERE,
+ base::Bind(&FileSystemContext::DeleteFileSystem,
+ file_system_context_,
+ test_helper_.origin(),
+ test_helper_.type()));
}
FileSystemOperation* CannedSyncableFileSystem::NewOperation() {
@@ -259,6 +296,17 @@ void CannedSyncableFileSystem::DoRemove(
NewOperation()->Remove(url, recursive, callback);
}
+void CannedSyncableFileSystem::DoWrite(
+ net::URLRequestContext* url_request_context,
+ const FileSystemURL& url, const GURL& blob_url,
+ const WriteCallback& callback) {
+ EXPECT_TRUE(is_filesystem_opened_);
+ WriteHelper* helper = new WriteHelper;
+ NewOperation()->Write(url_request_context, url, blob_url, 0,
+ base::Bind(&WriteHelper::DidWrite,
+ base::Owned(helper), callback));
+}
+
void CannedSyncableFileSystem::DidOpenFileSystem(
PlatformFileError result, const std::string& name, const GURL& root) {
result_ = result;
diff --git a/webkit/fileapi/syncable/canned_syncable_file_system.h b/webkit/fileapi/syncable/canned_syncable_file_system.h
index 359d53c..4fa634e 100644
--- a/webkit/fileapi/syncable/canned_syncable_file_system.h
+++ b/webkit/fileapi/syncable/canned_syncable_file_system.h
@@ -21,6 +21,10 @@ class SingleThreadTaskRunner;
class Thread;
}
+namespace net {
+class URLRequestContext;
+}
+
namespace quota {
class QuotaManager;
}
@@ -37,6 +41,7 @@ class LocalFileSyncContext;
class CannedSyncableFileSystem {
public:
typedef base::Callback<void(base::PlatformFileError)> StatusCallback;
+ typedef base::Callback<void(int64)> WriteCallback;
CannedSyncableFileSystem(const GURL& origin,
const std::string& service,
@@ -83,6 +88,10 @@ class CannedSyncableFileSystem {
base::PlatformFileError TruncateFile(const FileSystemURL& url, int64 size);
base::PlatformFileError Remove(const FileSystemURL& url, bool recursive);
+ // Returns the # of bytes written (>=0) or an error code (<0).
+ int64 Write(net::URLRequestContext* url_request_context,
+ const FileSystemURL& url, const GURL& blob_url);
+
// Pruges the file system local storage.
base::PlatformFileError DeleteFileSystem();
@@ -107,6 +116,10 @@ class CannedSyncableFileSystem {
void DoRemove(const FileSystemURL& url,
bool recursive,
const StatusCallback& callback);
+ void DoWrite(net::URLRequestContext* url_request_context,
+ const FileSystemURL& url,
+ const GURL& blob_url,
+ const WriteCallback& callback);
// Callbacks.
void DidOpenFileSystem(base::PlatformFileError result,
diff --git a/webkit/fileapi/syncable/local_file_change_tracker_unittest.cc b/webkit/fileapi/syncable/local_file_change_tracker_unittest.cc
index 5f01a8dc..2ce3efb 100644
--- a/webkit/fileapi/syncable/local_file_change_tracker_unittest.cc
+++ b/webkit/fileapi/syncable/local_file_change_tracker_unittest.cc
@@ -10,6 +10,7 @@
#include "base/message_loop_proxy.h"
#include "base/scoped_temp_dir.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/blob/mock_blob_url_request_context.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_task_runners.h"
#include "webkit/fileapi/syncable/canned_syncable_file_system.h"
@@ -18,12 +19,16 @@
#include "webkit/fileapi/syncable/syncable_file_system_util.h"
#include "webkit/quota/quota_manager.h"
+using webkit_blob::MockBlobURLRequestContext;
+using webkit_blob::ScopedTextBlob;
+
namespace fileapi {
class LocalFileChangeTrackerTest : public testing::Test {
public:
LocalFileChangeTrackerTest()
- : file_system_(GURL("http://example.com"), "test",
+ : message_loop_(MessageLoop::TYPE_IO),
+ file_system_(GURL("http://example.com"), "test",
base::MessageLoopProxy::current()) {}
virtual void SetUp() OVERRIDE {
@@ -157,17 +162,24 @@ TEST_F(LocalFileChangeTrackerTest, RestoreCreateAndModifyChanges) {
const char kPath0[] = "file a";
const char kPath1[] = "dir a";
const char kPath2[] = "dir a/dir";
- const char kPath3[] = "dir a/file";
+ const char kPath3[] = "dir a/file a";
+ const char kPath4[] = "dir a/file b";
- const char kPath4[] = "file b"; // To be copied from kPath0
- const char kPath5[] = "dir b"; // To be copied from kPath1
- const char kPath6[] = "dir b/dir"; // To be copied from kPath2
- const char kPath7[] = "dir b/file"; // To be copied from kPath3
+ const char kPath0Copy[] = "file b"; // To be copied from kPath0
+ const char kPath1Copy[] = "dir b"; // To be copied from kPath1
+ const char kPath2Copy[] = "dir b/dir"; // To be copied from kPath2
+ const char kPath3Copy[] = "dir b/file a"; // To be copied from kPath3
+ const char kPath4Copy[] = "dir b/file b"; // To be copied from kPath4
change_tracker()->GetChangedURLs(&urls);
urlset.insert(urls.begin(), urls.end());
ASSERT_EQ(0U, urlset.size());
+ const GURL blob_url("blob:test");
+ const std::string kData("Lorem ipsum.");
+ MockBlobURLRequestContext url_request_context;
+ ScopedTextBlob blob(url_request_context, blob_url, kData);
+
// Creates files and nested directories.
EXPECT_EQ(base::PLATFORM_FILE_OK,
file_system_.CreateFile(URL(kPath0))); // Creates a file.
@@ -179,16 +191,21 @@ TEST_F(LocalFileChangeTrackerTest, RestoreCreateAndModifyChanges) {
file_system_.CreateFile(URL(kPath3))); // Creates a file.
EXPECT_EQ(base::PLATFORM_FILE_OK,
file_system_.TruncateFile(URL(kPath3), 1)); // Modifies the file.
+ EXPECT_EQ(base::PLATFORM_FILE_OK,
+ file_system_.CreateFile(URL(kPath4))); // Creates another file.
+ EXPECT_EQ(static_cast<int64>(kData.size()),
+ file_system_.Write(&url_request_context,
+ URL(kPath4), blob_url)); // Modifies the file.
// Copies the file and the parent directory.
EXPECT_EQ(base::PLATFORM_FILE_OK,
- file_system_.Copy(URL(kPath0), URL(kPath4))); // Copy the file.
+ file_system_.Copy(URL(kPath0), URL(kPath0Copy))); // Copy the file.
EXPECT_EQ(base::PLATFORM_FILE_OK,
- file_system_.Copy(URL(kPath1), URL(kPath5))); // Copy the dir.
+ file_system_.Copy(URL(kPath1), URL(kPath1Copy))); // Copy the dir.
change_tracker()->GetChangedURLs(&urls);
urlset.insert(urls.begin(), urls.end());
- EXPECT_EQ(8U, urlset.size());
+ EXPECT_EQ(10U, urlset.size());
DropChangesInTracker();
@@ -206,7 +223,7 @@ TEST_F(LocalFileChangeTrackerTest, RestoreCreateAndModifyChanges) {
urlset.clear();
change_tracker()->GetChangedURLs(&urls);
urlset.insert(urls.begin(), urls.end());
- EXPECT_EQ(8U, urlset.size());
+ EXPECT_EQ(10U, urlset.size());
VerifyAndClearChange(URL(kPath0),
FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
@@ -223,13 +240,20 @@ TEST_F(LocalFileChangeTrackerTest, RestoreCreateAndModifyChanges) {
VerifyAndClearChange(URL(kPath4),
FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
FileChange::FILE_TYPE_FILE));
- VerifyAndClearChange(URL(kPath5),
+
+ VerifyAndClearChange(URL(kPath0Copy),
+ FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
+ FileChange::FILE_TYPE_FILE));
+ VerifyAndClearChange(URL(kPath1Copy),
FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
FileChange::FILE_TYPE_DIRECTORY));
- VerifyAndClearChange(URL(kPath6),
+ VerifyAndClearChange(URL(kPath2Copy),
FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
FileChange::FILE_TYPE_DIRECTORY));
- VerifyAndClearChange(URL(kPath7),
+ VerifyAndClearChange(URL(kPath3Copy),
+ FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
+ FileChange::FILE_TYPE_FILE));
+ VerifyAndClearChange(URL(kPath4Copy),
FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
FileChange::FILE_TYPE_FILE));
}
diff --git a/webkit/fileapi/syncable/local_file_sync_context_unittest.cc b/webkit/fileapi/syncable/local_file_sync_context_unittest.cc
index 48aca29..e711f4a 100644
--- a/webkit/fileapi/syncable/local_file_sync_context_unittest.cc
+++ b/webkit/fileapi/syncable/local_file_sync_context_unittest.cc
@@ -42,7 +42,8 @@ class LocalFileSyncContextTest : public testing::Test {
io_thread_.reset(new base::Thread("Thread_IO"));
file_thread_.reset(new base::Thread("Thread_File"));
- io_thread_->Start();
+ io_thread_->StartWithOptions(
+ base::Thread::Options(MessageLoop::TYPE_IO, 0));
file_thread_->Start();
ui_task_runner_ = MessageLoop::current()->message_loop_proxy();