Commit 2b6eb3da authored by mtomasz@chromium.org's avatar mtomasz@chromium.org

[fsp] Add support for creating directories.

This is the first R/W operation. The new event in IDL has [nodoc], since we
don't want to show it on developer.chrome.com before most of the R/W features
are done.

TEST=unit_tests, browser_tests: *FileSystemProvider*CreateDirectory*
BUG=391362

Review URL: https://codereview.chromium.org/366263002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282554 0039d316-1c4b-4281-b951-d872f2087c98
parent e7ff2bca
...@@ -74,4 +74,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, MimeType) { ...@@ -74,4 +74,10 @@ IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, MimeType) {
<< message_; << message_;
} }
IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, CreateDirectory) {
ASSERT_TRUE(RunPlatformAppTestWithFlags(
"file_system_provider/create_directory", kFlagLoadAsComponent))
<< message_;
}
} // namespace extensions } // namespace extensions
...@@ -227,6 +227,15 @@ void FakeProvidedFileSystem::ReadFile( ...@@ -227,6 +227,15 @@ void FakeProvidedFileSystem::ReadFile(
} }
} }
void FakeProvidedFileSystem::CreateDirectory(
const base::FilePath& directory_path,
bool exclusive,
bool recursive,
const fileapi::AsyncFileUtil::StatusCallback& callback) {
base::MessageLoopProxy::current()->PostTask(
FROM_HERE, base::Bind(callback, base::File::FILE_OK));
}
const ProvidedFileSystemInfo& FakeProvidedFileSystem::GetFileSystemInfo() const ProvidedFileSystemInfo& FakeProvidedFileSystem::GetFileSystemInfo()
const { const {
return file_system_info_; return file_system_info_;
......
...@@ -57,6 +57,11 @@ class FakeProvidedFileSystem : public ProvidedFileSystemInterface { ...@@ -57,6 +57,11 @@ class FakeProvidedFileSystem : public ProvidedFileSystemInterface {
int64 offset, int64 offset,
int length, int length,
const ReadChunkReceivedCallback& callback) OVERRIDE; const ReadChunkReceivedCallback& callback) OVERRIDE;
virtual void CreateDirectory(
const base::FilePath& directory_path,
bool exclusive,
bool recursive,
const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const OVERRIDE; virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const OVERRIDE;
virtual RequestManager* GetRequestManager() OVERRIDE; virtual RequestManager* GetRequestManager() OVERRIDE;
virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() OVERRIDE; virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() OVERRIDE;
......
...@@ -83,6 +83,30 @@ void OnReadDirectory( ...@@ -83,6 +83,30 @@ void OnReadDirectory(
base::Bind(callback, result, entry_list, has_more)); base::Bind(callback, result, entry_list, has_more));
} }
// Executes CreateDirectory on the UI thread.
void CreateDirectoryOnUIThread(
scoped_ptr<fileapi::FileSystemOperationContext> context,
const fileapi::FileSystemURL& url,
bool exclusive,
bool recursive,
const fileapi::AsyncFileUtil::StatusCallback& callback) {
util::FileSystemURLParser parser(url);
if (!parser.Parse()) {
callback.Run(base::File::FILE_ERROR_INVALID_OPERATION);
return;
}
parser.file_system()->CreateDirectory(
parser.file_path(), exclusive, recursive, callback);
}
// Routes the response of CreateDirectory back to the IO thread.
void OnCreateDirectory(const fileapi::AsyncFileUtil::StatusCallback& callback,
base::File::Error result) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, base::Bind(callback, result));
}
} // namespace } // namespace
ProviderAsyncFileUtil::ProviderAsyncFileUtil() {} ProviderAsyncFileUtil::ProviderAsyncFileUtil() {}
...@@ -124,7 +148,14 @@ void ProviderAsyncFileUtil::CreateDirectory( ...@@ -124,7 +148,14 @@ void ProviderAsyncFileUtil::CreateDirectory(
bool recursive, bool recursive,
const StatusCallback& callback) { const StatusCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
callback.Run(base::File::FILE_ERROR_ACCESS_DENIED); BrowserThread::PostTask(BrowserThread::UI,
FROM_HERE,
base::Bind(&CreateDirectoryOnUIThread,
base::Passed(&context),
url,
exclusive,
recursive,
base::Bind(&OnCreateDirectory, callback)));
} }
void ProviderAsyncFileUtil::GetFileInfo( void ProviderAsyncFileUtil::GetFileInfo(
......
// Copyright 2014 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 "chrome/browser/chromeos/file_system_provider/operations/create_directory.h"
#include <string>
#include "chrome/common/extensions/api/file_system_provider.h"
#include "chrome/common/extensions/api/file_system_provider_internal.h"
namespace chromeos {
namespace file_system_provider {
namespace operations {
CreateDirectory::CreateDirectory(
extensions::EventRouter* event_router,
const ProvidedFileSystemInfo& file_system_info,
const base::FilePath& directory_path,
bool exclusive,
bool recursive,
const fileapi::AsyncFileUtil::StatusCallback& callback)
: Operation(event_router, file_system_info),
directory_path_(directory_path),
exclusive_(exclusive),
recursive_(recursive),
callback_(callback) {
}
CreateDirectory::~CreateDirectory() {
}
bool CreateDirectory::Execute(int request_id) {
scoped_ptr<base::DictionaryValue> values(new base::DictionaryValue);
values->SetString("directoryPath", directory_path_.AsUTF8Unsafe());
values->SetBoolean("exclusive", exclusive_);
values->SetBoolean("recursive", recursive_);
return SendEvent(request_id,
extensions::api::file_system_provider::
OnCreateDirectoryRequested::kEventName,
values.Pass());
}
void CreateDirectory::OnSuccess(int /* request_id */,
scoped_ptr<RequestValue> /* result */,
bool has_more) {
callback_.Run(base::File::FILE_OK);
}
void CreateDirectory::OnError(int /* request_id */,
scoped_ptr<RequestValue> /* result */,
base::File::Error error) {
callback_.Run(error);
}
} // namespace operations
} // namespace file_system_provider
} // namespace chromeos
// Copyright 2014 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 CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_CREATE_DIRECTORY_H_
#define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_CREATE_DIRECTORY_H_
#include "base/files/file.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/file_system_provider/operations/operation.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
#include "chrome/browser/chromeos/file_system_provider/request_value.h"
#include "webkit/browser/fileapi/async_file_util.h"
namespace base {
class FilePath;
} // namespace base
namespace extensions {
class EventRouter;
} // namespace extensions
namespace chromeos {
namespace file_system_provider {
namespace operations {
// Creates a directory. If |recursive| is set to true, then creates also all
// non-existing directories on the path. If |exclusive| is true, then the
// operation will fail if the directory already exists. Created per request.
class CreateDirectory : public Operation {
public:
CreateDirectory(extensions::EventRouter* event_router,
const ProvidedFileSystemInfo& file_system_info,
const base::FilePath& directory_path,
bool exclusive,
bool recursive,
const fileapi::AsyncFileUtil::StatusCallback& callback);
virtual ~CreateDirectory();
// Operation overrides.
virtual bool Execute(int request_id) OVERRIDE;
virtual void OnSuccess(int request_id,
scoped_ptr<RequestValue> result,
bool has_more) OVERRIDE;
virtual void OnError(int request_id,
scoped_ptr<RequestValue> result,
base::File::Error error) OVERRIDE;
private:
base::FilePath directory_path_;
ProvidedFileSystemInterface::OpenFileMode mode_;
bool exclusive_;
bool recursive_;
const fileapi::AsyncFileUtil::StatusCallback callback_;
DISALLOW_COPY_AND_ASSIGN(CreateDirectory);
};
} // namespace operations
} // namespace file_system_provider
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_OPERATIONS_CREATE_DIRECTORY_H_
// Copyright 2014 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 <string>
#include <vector>
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "chrome/browser/chromeos/file_system_provider/operations/create_directory.h"
#include "chrome/browser/chromeos/file_system_provider/operations/test_util.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
#include "chrome/common/extensions/api/file_system_provider.h"
#include "chrome/common/extensions/api/file_system_provider_internal.h"
#include "extensions/browser/event_router.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/browser/fileapi/async_file_util.h"
namespace chromeos {
namespace file_system_provider {
namespace operations {
namespace {
const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj";
const char kFileSystemId[] = "testing-file-system";
const int kRequestId = 2;
const base::FilePath::CharType kDirectoryPath[] = "/kitty/and/puppy/happy";
} // namespace
class FileSystemProviderOperationsCreateDirectoryTest : public testing::Test {
protected:
FileSystemProviderOperationsCreateDirectoryTest() {}
virtual ~FileSystemProviderOperationsCreateDirectoryTest() {}
virtual void SetUp() OVERRIDE {
file_system_info_ =
ProvidedFileSystemInfo(kExtensionId,
kFileSystemId,
"" /* file_system_name */,
base::FilePath() /* mount_path */);
}
ProvidedFileSystemInfo file_system_info_;
};
TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute) {
util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
util::StatusCallbackLog callback_log;
CreateDirectory create_directory(
NULL,
file_system_info_,
base::FilePath::FromUTF8Unsafe(kDirectoryPath),
false /* exclusive */,
true /* recursive */,
base::Bind(&util::LogStatusCallback, &callback_log));
create_directory.SetDispatchEventImplForTesting(
base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
base::Unretained(&dispatcher)));
EXPECT_TRUE(create_directory.Execute(kRequestId));
ASSERT_EQ(1u, dispatcher.events().size());
extensions::Event* event = dispatcher.events()[0];
EXPECT_EQ(extensions::api::file_system_provider::OnCreateDirectoryRequested::
kEventName,
event->event_name);
base::ListValue* event_args = event->event_args.get();
ASSERT_EQ(1u, event_args->GetSize());
base::DictionaryValue* options = NULL;
ASSERT_TRUE(event_args->GetDictionary(0, &options));
std::string event_file_system_id;
EXPECT_TRUE(options->GetString("fileSystemId", &event_file_system_id));
EXPECT_EQ(kFileSystemId, event_file_system_id);
int event_request_id = -1;
EXPECT_TRUE(options->GetInteger("requestId", &event_request_id));
EXPECT_EQ(kRequestId, event_request_id);
std::string event_directory_path;
EXPECT_TRUE(options->GetString("directoryPath", &event_directory_path));
EXPECT_EQ(kDirectoryPath, event_directory_path);
bool event_exclusive;
EXPECT_TRUE(options->GetBoolean("exclusive", &event_exclusive));
EXPECT_FALSE(event_exclusive);
bool event_recursive;
EXPECT_TRUE(options->GetBoolean("recursive", &event_recursive));
EXPECT_TRUE(event_recursive);
}
TEST_F(FileSystemProviderOperationsCreateDirectoryTest, Execute_NoListener) {
util::LoggingDispatchEventImpl dispatcher(false /* dispatch_reply */);
util::StatusCallbackLog callback_log;
CreateDirectory create_directory(
NULL,
file_system_info_,
base::FilePath::FromUTF8Unsafe(kDirectoryPath),
false /* exclusive */,
true /* recursive */,
base::Bind(&util::LogStatusCallback, &callback_log));
create_directory.SetDispatchEventImplForTesting(
base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
base::Unretained(&dispatcher)));
EXPECT_FALSE(create_directory.Execute(kRequestId));
}
TEST_F(FileSystemProviderOperationsCreateDirectoryTest, OnSuccess) {
util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
util::StatusCallbackLog callback_log;
CreateDirectory create_directory(
NULL,
file_system_info_,
base::FilePath::FromUTF8Unsafe(kDirectoryPath),
false /* exclusive */,
true /* recursive */,
base::Bind(&util::LogStatusCallback, &callback_log));
create_directory.SetDispatchEventImplForTesting(
base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
base::Unretained(&dispatcher)));
EXPECT_TRUE(create_directory.Execute(kRequestId));
create_directory.OnSuccess(kRequestId,
scoped_ptr<RequestValue>(new RequestValue()),
false /* has_more */);
ASSERT_EQ(1u, callback_log.size());
EXPECT_EQ(base::File::FILE_OK, callback_log[0]);
}
TEST_F(FileSystemProviderOperationsCreateDirectoryTest, OnError) {
util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */);
util::StatusCallbackLog callback_log;
CreateDirectory create_directory(
NULL,
file_system_info_,
base::FilePath::FromUTF8Unsafe(kDirectoryPath),
false /* exclusive */,
true /* recursive */,
base::Bind(&util::LogStatusCallback, &callback_log));
create_directory.SetDispatchEventImplForTesting(
base::Bind(&util::LoggingDispatchEventImpl::OnDispatchEventImpl,
base::Unretained(&dispatcher)));
EXPECT_TRUE(create_directory.Execute(kRequestId));
create_directory.OnError(kRequestId,
scoped_ptr<RequestValue>(new RequestValue()),
base::File::FILE_ERROR_TOO_MANY_OPENED);
ASSERT_EQ(1u, callback_log.size());
EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, callback_log[0]);
}
} // namespace operations
} // namespace file_system_provider
} // namespace chromeos
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/files/file.h" #include "base/files/file.h"
#include "chrome/browser/chromeos/file_system_provider/notification_manager.h" #include "chrome/browser/chromeos/file_system_provider/notification_manager.h"
#include "chrome/browser/chromeos/file_system_provider/operations/close_file.h" #include "chrome/browser/chromeos/file_system_provider/operations/close_file.h"
#include "chrome/browser/chromeos/file_system_provider/operations/create_directory.h"
#include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.h" #include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.h"
#include "chrome/browser/chromeos/file_system_provider/operations/open_file.h" #include "chrome/browser/chromeos/file_system_provider/operations/open_file.h"
#include "chrome/browser/chromeos/file_system_provider/operations/read_directory.h" #include "chrome/browser/chromeos/file_system_provider/operations/read_directory.h"
...@@ -130,6 +131,24 @@ void ProvidedFileSystem::CloseFile( ...@@ -130,6 +131,24 @@ void ProvidedFileSystem::CloseFile(
} }
} }
void ProvidedFileSystem::CreateDirectory(
const base::FilePath& directory_path,
bool exclusive,
bool recursive,
const fileapi::AsyncFileUtil::StatusCallback& callback) {
if (!request_manager_.CreateRequest(
CREATE_DIRECTORY,
scoped_ptr<RequestManager::HandlerInterface>(
new operations::CreateDirectory(event_router_,
file_system_info_,
directory_path,
exclusive,
recursive,
callback)))) {
callback.Run(base::File::FILE_ERROR_SECURITY);
}
}
const ProvidedFileSystemInfo& ProvidedFileSystem::GetFileSystemInfo() const { const ProvidedFileSystemInfo& ProvidedFileSystem::GetFileSystemInfo() const {
return file_system_info_; return file_system_info_;
} }
......
...@@ -57,6 +57,11 @@ class ProvidedFileSystem : public ProvidedFileSystemInterface { ...@@ -57,6 +57,11 @@ class ProvidedFileSystem : public ProvidedFileSystemInterface {
int64 offset, int64 offset,
int length, int length,
const ReadChunkReceivedCallback& callback) OVERRIDE; const ReadChunkReceivedCallback& callback) OVERRIDE;
virtual void CreateDirectory(
const base::FilePath& directory_path,
bool exclusive,
bool recursive,
const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const OVERRIDE; virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const OVERRIDE;
virtual RequestManager* GetRequestManager() OVERRIDE; virtual RequestManager* GetRequestManager() OVERRIDE;
virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() OVERRIDE; virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() OVERRIDE;
......
...@@ -100,6 +100,15 @@ class ProvidedFileSystemInterface { ...@@ -100,6 +100,15 @@ class ProvidedFileSystemInterface {
int length, int length,
const ReadChunkReceivedCallback& callback) = 0; const ReadChunkReceivedCallback& callback) = 0;
// Requests creating a directory. If |recursive| is passed, then all non
// existing directories on the path will be created. If |exclusive| is true,
// then creating the directory will fail, if it already exists.
virtual void CreateDirectory(
const base::FilePath& directory_path,
bool exclusive,
bool recursive,
const fileapi::AsyncFileUtil::StatusCallback& callback) = 0;
// Returns a provided file system info for this file system. // Returns a provided file system info for this file system.
virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const = 0; virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const = 0;
......
...@@ -32,6 +32,8 @@ std::string RequestTypeToString(RequestType type) { ...@@ -32,6 +32,8 @@ std::string RequestTypeToString(RequestType type) {
return "CLOSE_FILE"; return "CLOSE_FILE";
case READ_FILE: case READ_FILE:
return "READ_FILE"; return "READ_FILE";
case CREATE_DIRECTORY:
return "CREATE_DIRECTORY";
case TESTING: case TESTING:
return "TESTING"; return "TESTING";
} }
......
...@@ -30,6 +30,7 @@ enum RequestType { ...@@ -30,6 +30,7 @@ enum RequestType {
OPEN_FILE, OPEN_FILE,
CLOSE_FILE, CLOSE_FILE,
READ_FILE, READ_FILE,
CREATE_DIRECTORY,
TESTING TESTING
}; };
......
...@@ -394,6 +394,8 @@ ...@@ -394,6 +394,8 @@
'browser/chromeos/file_system_provider/observer.h', 'browser/chromeos/file_system_provider/observer.h',
'browser/chromeos/file_system_provider/operations/close_file.cc', 'browser/chromeos/file_system_provider/operations/close_file.cc',
'browser/chromeos/file_system_provider/operations/close_file.h', 'browser/chromeos/file_system_provider/operations/close_file.h',
'browser/chromeos/file_system_provider/operations/create_directory.cc',
'browser/chromeos/file_system_provider/operations/create_directory.h',
'browser/chromeos/file_system_provider/operations/get_metadata.cc', 'browser/chromeos/file_system_provider/operations/get_metadata.cc',
'browser/chromeos/file_system_provider/operations/get_metadata.h', 'browser/chromeos/file_system_provider/operations/get_metadata.h',
'browser/chromeos/file_system_provider/operations/open_file.cc', 'browser/chromeos/file_system_provider/operations/open_file.cc',
......
...@@ -742,7 +742,10 @@ ...@@ -742,7 +742,10 @@
'browser/chromeos/file_system_provider/fileapi/file_stream_reader_unittest.cc', 'browser/chromeos/file_system_provider/fileapi/file_stream_reader_unittest.cc',
'browser/chromeos/file_system_provider/fileapi/provider_async_file_util_unittest.cc', 'browser/chromeos/file_system_provider/fileapi/provider_async_file_util_unittest.cc',
'browser/chromeos/file_system_provider/mount_path_util_unittest.cc', 'browser/chromeos/file_system_provider/mount_path_util_unittest.cc',
'browser/chromeos/file_system_provider/operations/test_util.cc',
'browser/chromeos/file_system_provider/operations/test_util.h',
'browser/chromeos/file_system_provider/operations/close_file_unittest.cc', 'browser/chromeos/file_system_provider/operations/close_file_unittest.cc',
'browser/chromeos/file_system_provider/operations/create_directory_unittest.cc',
'browser/chromeos/file_system_provider/operations/get_metadata_unittest.cc', 'browser/chromeos/file_system_provider/operations/get_metadata_unittest.cc',
'browser/chromeos/file_system_provider/operations/open_file_unittest.cc', 'browser/chromeos/file_system_provider/operations/open_file_unittest.cc',
'browser/chromeos/file_system_provider/operations/read_directory_unittest.cc', 'browser/chromeos/file_system_provider/operations/read_directory_unittest.cc',
......
...@@ -108,6 +108,15 @@ namespace fileSystemProvider { ...@@ -108,6 +108,15 @@ namespace fileSystemProvider {
double length; double length;
}; };
// Options for the <code>onCreateDirectoryRequested()</code> event.
dictionary CreateDirectoryRequestedOptions {
DOMString fileSystemId;
long requestId;
DOMString directoryPath;
boolean exclusive;
boolean recursive;
};
// Callback to receive the result of mount() function. // Callback to receive the result of mount() function.
callback MountCallback = void([nodoc, instanceOf=DOMError] object error); callback MountCallback = void([nodoc, instanceOf=DOMError] object error);
...@@ -216,6 +225,15 @@ namespace fileSystemProvider { ...@@ -216,6 +225,15 @@ namespace fileSystemProvider {
ReadFileRequestedOptions options, ReadFileRequestedOptions options,
FileDataCallback successCallback, FileDataCallback successCallback,
ProviderErrorCallback errorCallback); ProviderErrorCallback errorCallback);
// Raised when creating a directory is requested. If <code>exclusive</code>
// is set to true, then the operation should fail if the target directory
// already exists. If <code>recursive</code> is true, then all of the
// missing directories on the directory path should be created.
[maxListeners=1, nodoc] static void onCreateDirectoryRequested(
CreateDirectoryRequestedOptions options,
ProviderSuccessCallback successCallback,
ProviderErrorCallback errorCallback);
}; };
}; };
...@@ -41,6 +41,28 @@ function annotateMetadata(metadata) { ...@@ -41,6 +41,28 @@ function annotateMetadata(metadata) {
return result; return result;
} }
/**
* Massages arguments of an event raised by the File System Provider API.
* @param {Array.<*>} args Input arguments.
* @param {function(Array.<*>)} dispatch Closure to be called with massaged
* arguments.
*/
function massageArgumentsDefault(args, dispatch) {
var executionStart = Date.now();
var options = args[0];
var onSuccessCallback = function(hasNext) {
fileSystemProviderInternal.operationRequestedSuccess(
options.fileSystemId, options.requestId, Date.now() - executionStart);
};
var onErrorCallback = function(error) {
fileSystemProviderInternal.operationRequestedError(
options.fileSystemId, options.requestId, error,
Date.now() - executionStart);
}
dispatch([options, onSuccessCallback, onErrorCallback]);
}
binding.registerCustomHook(function(bindingsAPI) { binding.registerCustomHook(function(bindingsAPI) {
var apiFunctions = bindingsAPI.apiFunctions; var apiFunctions = bindingsAPI.apiFunctions;
...@@ -111,21 +133,7 @@ binding.registerCustomHook(function(bindingsAPI) { ...@@ -111,21 +133,7 @@ binding.registerCustomHook(function(bindingsAPI) {
eventBindings.registerArgumentMassager( eventBindings.registerArgumentMassager(
'fileSystemProvider.onUnmountRequested', 'fileSystemProvider.onUnmountRequested',
function(args, dispatch) { massageArgumentsDefault);
var executionStart = Date.now();
var options = args[0];
var onSuccessCallback = function() {
fileSystemProviderInternal.unmountRequestedSuccess(
options.fileSystemId, options.requestId,
Date.now() - executionStart);
};
var onErrorCallback = function(error) {
fileSystemProviderInternal.operationRequestedError(
options.fileSystemId, options.requestId, error,
Date.now() - executionStart);
}
dispatch([options, onSuccessCallback, onErrorCallback]);
});
eventBindings.registerArgumentMassager( eventBindings.registerArgumentMassager(
'fileSystemProvider.onGetMetadataRequested', 'fileSystemProvider.onGetMetadataRequested',
...@@ -168,39 +176,11 @@ eventBindings.registerArgumentMassager( ...@@ -168,39 +176,11 @@ eventBindings.registerArgumentMassager(
eventBindings.registerArgumentMassager( eventBindings.registerArgumentMassager(
'fileSystemProvider.onOpenFileRequested', 'fileSystemProvider.onOpenFileRequested',
function(args, dispatch) { massageArgumentsDefault);
var executionStart = Date.now();
var options = args[0];
var onSuccessCallback = function() {
fileSystemProviderInternal.operationRequestedSuccess(
options.fileSystemId, options.requestId,
Date.now() - executionStart);
};
var onErrorCallback = function(error) {
fileSystemProviderInternal.operationRequestedError(
options.fileSystemId, options.requestId, error,
Date.now() - executionStart);
}
dispatch([options, onSuccessCallback, onErrorCallback]);
});
eventBindings.registerArgumentMassager( eventBindings.registerArgumentMassager(
'fileSystemProvider.onCloseFileRequested', 'fileSystemProvider.onCloseFileRequested',
function(args, dispatch) { massageArgumentsDefault);
var executionStart = Date.now();
var options = args[0];
var onSuccessCallback = function() {
fileSystemProviderInternal.operationRequestedSuccess(
options.fileSystemId, options.requestId,
Date.now() - executionStart);
};
var onErrorCallback = function(error) {
fileSystemProviderInternal.operationRequestedError(
options.fileSystemId, options.requestId, error,
Date.now() - executionStart);
}
dispatch([options, onSuccessCallback, onErrorCallback]);
});
eventBindings.registerArgumentMassager( eventBindings.registerArgumentMassager(
'fileSystemProvider.onReadFileRequested', 'fileSystemProvider.onReadFileRequested',
...@@ -220,4 +200,8 @@ eventBindings.registerArgumentMassager( ...@@ -220,4 +200,8 @@ eventBindings.registerArgumentMassager(
dispatch([options, onSuccessCallback, onErrorCallback]); dispatch([options, onSuccessCallback, onErrorCallback]);
}); });
eventBindings.registerArgumentMassager(
'fileSystemProvider.onCreateDirectoryRequested',
massageArgumentsDefault);
exports.binding = binding.generate(); exports.binding = binding.generate();
{
"key": "MIGdMA0GCSqGSIb3DQEBAQUAA4GLADCBhwKBgQDOuXEIuoK1kAkBe0SKiJn/N9oNn3oUxGa4dwj40MnJqPn+w0aR2vuyocm0R4Drp67aYwtLjOVPF4CICRq6ICP6eU07gGwQxGdZ7HJASXV8hm0tab5I70oJmRLfFJyVAMCeWlFaOGq05v2i6EbifZM0qO5xALKNGQt+yjXi5INM5wIBIw==",
"name": "chrome.fileSystemProvider.onCreateDirectoryRequested",
"version": "0.1",
"manifest_version": 2,
"description":
"Test for chrome.fileSystemProvider.onCreateDirectoryRequested().",
"permissions": [
"fileSystemProvider",
"fileBrowserPrivate",
"fileBrowserHandler"
],
"app": {
"background": {
"scripts": [
"chrome-extension://gfnblenhaahcnmfdbebgincjohfkbnch/test_util.js",
"test.js"
]
}
}
}
// Copyright 2014 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.
'use strict';
/**
* @type {Object}
* @const
*/
var TESTING_DIRECTORY = Object.freeze({
isDirectory: false,
name: 'kitty',
size: 0,
modificationTime: new Date(2014, 4, 28, 10, 39, 15)
});
/**
* Creates a directory.
*
* @param {CreateDirectoryRequestedOptions} options Options.
* @param {function(Object)} onSuccess Success callback
* @param {function(string)} onError Error callback with an error code.
*/
function onCreateDirectoryRequested(options, onSuccess, onError) {
if (options.fileSystemId != test_util.FILE_SYSTEM_ID) {
onError('SECURITY'); // enum ProviderError.
return;
}
if (options.directoryPath == '/' || options.recursive) {
onError('INVALID_OPERATION');
return;
}
if (options.exclusive && (options.directoryPath in
test_util.defaultMetadata)) {
onError('EXISTS');
return;
}
test_util.defaultMetadata[options.directoryPath] = TESTING_DIRECTORY;
onSuccess(); // enum ProviderError.
}
/**
* Sets up the tests. Called once per all test cases. In case of a failure,
* the callback is not called.
*
* @param {function()} callback Success callback.
*/
function setUp(callback) {
chrome.fileSystemProvider.onGetMetadataRequested.addListener(
test_util.onGetMetadataRequestedDefault);
test_util.defaultMetadata['/' + TESTING_DIRECTORY.name] =
TESTING_DIRECTORY;
chrome.fileSystemProvider.onCreateDirectoryRequested.addListener(
onCreateDirectoryRequested);
test_util.mountFileSystem(callback);
}
/**
* Runs all of the test cases, one by one.
*/
function runTests() {
chrome.test.runTests([
// Create a directory (not exclusive). Should succeed.
function createDirectorySuccessSimple() {
var onSuccess = chrome.test.callbackPass();
test_util.fileSystem.root.getDirectory(
TESTING_DIRECTORY.name, {create: true, exclusive: false},
function(entry) {
chrome.test.assertEq(TESTING_DIRECTORY.name, entry.name);
chrome.test.assertTrue(entry.isDirectory);
onSuccess();
}, function(error) {
chrome.test.fail(error.name);
});
},
// Create a directory (exclusive). Should fail, since the directory already
// exists.
function createDirectoryErrorExists() {
var onSuccess = chrome.test.callbackPass();
test_util.fileSystem.root.getDirectory(
TESTING_DIRECTORY.name, {create: true, exclusive: true},
function(entry) {
chrome.test.fail('Created a directory, but should fail.');
}, function(error) {
chrome.test.assertEq('InvalidModificationError', error.name);
onSuccess();
});
},
]);
}
// Setup and run all of the test cases.
setUp(runTests);
...@@ -4,11 +4,6 @@ ...@@ -4,11 +4,6 @@
'use strict'; 'use strict';
/**
* @type {DOMFileSystem}
*/
var fileSystem = null;
/** /**
* Map of opened files, from a <code>openRequestId</code> to <code>filePath * Map of opened files, from a <code>openRequestId</code> to <code>filePath
* </code>. * </code>.
......
...@@ -4,11 +4,6 @@ ...@@ -4,11 +4,6 @@
'use strict'; 'use strict';
/**
* @type {DOMFileSystem}
*/
var fileSystem = null;
/** /**
* @type {string} * @type {string}
* @const * @const
......
...@@ -4,11 +4,6 @@ ...@@ -4,11 +4,6 @@
'use strict'; 'use strict';
/**
* @type {DOMFileSystem}
*/
var fileSystem = null;
/** /**
* @type {Object} * @type {Object}
* @const * @const
......
...@@ -4,11 +4,6 @@ ...@@ -4,11 +4,6 @@
'use strict'; 'use strict';
/**
* @type {DOMFileSystem}
*/
var fileSystem = null;
/** /**
* Map of opened files, from a <code>openRequestId</code> to <code>filePath * Map of opened files, from a <code>openRequestId</code> to <code>filePath
* </code>. * </code>.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment