| Index: webkit/browser/fileapi/async_file_util_test_helper.cc
|
| diff --git a/webkit/browser/fileapi/async_file_util_test_helper.cc b/webkit/browser/fileapi/async_file_util_test_helper.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b982c153f7628baf85859e9c6fea727c7a15f98c
|
| --- /dev/null
|
| +++ b/webkit/browser/fileapi/async_file_util_test_helper.cc
|
| @@ -0,0 +1,324 @@
|
| +// Copyright 2013 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/browser/fileapi/async_file_util_test_helper.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/files/file_path.h"
|
| +#include "base/platform_file.h"
|
| +#include "base/run_loop.h"
|
| +#include "webkit/common/blob/scoped_file.h"
|
| +#include "webkit/common/blob/shareable_file_reference.h"
|
| +
|
| +namespace fileapi {
|
| +
|
| +namespace {
|
| +
|
| +// Needed as base::Bind only supports functions of up to arity 7.
|
| +struct CreateSnapshotResults {
|
| + scoped_refptr<webkit_blob::ShareableFileReference>* file_ref;
|
| + base::PlatformFileError* error;
|
| + base::PlatformFileInfo* file_info;
|
| + base::FilePath* platform_path;
|
| +};
|
| +
|
| +void CreateOrOpenTestCallback(
|
| + base::RunLoop* run_loop,
|
| + base::PlatformFileError* error_result,
|
| + base::PlatformFile* platform_file_result,
|
| + bool* created_result,
|
| + base::PlatformFileError error,
|
| + base::PassPlatformFile pass_platform_file,
|
| + bool created) {
|
| + DCHECK(error_result);
|
| + DCHECK(platform_file_result);
|
| + DCHECK(created_result);
|
| + *error_result = error;
|
| + *platform_file_result = pass_platform_file.ReleaseValue();
|
| + *created_result = created;
|
| + run_loop->Quit();
|
| +}
|
| +
|
| +void CreateSnapshotTestCallback(
|
| + base::RunLoop* run_loop,
|
| + CreateSnapshotResults* results,
|
| + base::PlatformFileError error,
|
| + const base::PlatformFileInfo& file_info,
|
| + const base::FilePath& platform_path,
|
| + const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) {
|
| + DCHECK(results->file_ref);
|
| + DCHECK(results->error);
|
| + DCHECK(results->file_info);
|
| + DCHECK(results->platform_path);
|
| + *(results->error) = error;
|
| + *(results->file_info) = file_info;
|
| + *(results->platform_path) = platform_path;
|
| + *(results->file_ref) = file_ref;
|
| + run_loop->Quit();
|
| +}
|
| +
|
| +void EnsureFileExistsTestCallback(
|
| + base::RunLoop* run_loop,
|
| + base::PlatformFileError* error_result,
|
| + bool* created_result,
|
| + base::PlatformFileError error,
|
| + bool created) {
|
| + DCHECK(error_result);
|
| + DCHECK(created_result);
|
| + *error_result = error;
|
| + *created_result = created;
|
| + run_loop->Quit();
|
| +}
|
| +
|
| +void GetFileInfoTestCallback(
|
| + base::RunLoop* run_loop,
|
| + base::PlatformFileError* error_result,
|
| + base::PlatformFileInfo* file_info_result,
|
| + base::FilePath* platform_path_result,
|
| + base::PlatformFileError error,
|
| + const base::PlatformFileInfo& file_info,
|
| + const base::FilePath& platform_path) {
|
| + DCHECK(error_result);
|
| + DCHECK(file_info_result);
|
| + DCHECK(platform_path_result);
|
| + *error_result = error;
|
| + *file_info_result = file_info;
|
| + *platform_path_result = platform_path;
|
| + run_loop->Quit();
|
| +}
|
| +
|
| +void ReadDirectoryTestCallback(
|
| + base::RunLoop* run_loop,
|
| + base::PlatformFileError* error_result,
|
| + AsyncFileUtil::EntryList* file_list_result,
|
| + bool* has_more_result,
|
| + base::PlatformFileError error,
|
| + const AsyncFileUtil::EntryList& file_list,
|
| + bool has_more) {
|
| + DCHECK(error_result);
|
| + DCHECK(file_list_result);
|
| + DCHECK(has_more_result);
|
| + *error_result = error;
|
| + *file_list_result = file_list;
|
| + *has_more_result = has_more;
|
| + run_loop->Quit();
|
| +}
|
| +
|
| +void StatusTestCallback(
|
| + base::RunLoop* run_loop,
|
| + base::PlatformFileError* error_result,
|
| + base::PlatformFileError error) {
|
| + DCHECK(error_result);
|
| + *error_result = error;
|
| + run_loop->Quit();
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +AsyncFileUtilTestHelper::AsyncFileUtilTestHelper(AsyncFileUtil* async_file_util)
|
| + : async_file_util_(async_file_util) {
|
| +}
|
| +
|
| +AsyncFileUtilTestHelper::~AsyncFileUtilTestHelper() {}
|
| +
|
| +base::PlatformFileError AsyncFileUtilTestHelper::CreateOrOpen(
|
| + FileSystemOperationContext* context,
|
| + const FileSystemURL& url,
|
| + int file_flags,
|
| + base::PlatformFile* file_handle,
|
| + bool* created) {
|
| + DCHECK(context);
|
| + base::PlatformFileError result;
|
| + base::RunLoop run_loop;
|
| + async_file_util_->CreateOrOpen(
|
| + context,
|
| + url,
|
| + file_flags,
|
| + base::Bind(
|
| + &CreateOrOpenTestCallback,
|
| + &run_loop,
|
| + &result,
|
| + file_handle,
|
| + created));
|
| + run_loop.Run();
|
| + return result;
|
| +}
|
| +
|
| +base::PlatformFileError AsyncFileUtilTestHelper::Close(
|
| + FileSystemOperationContext* context,
|
| + base::PlatformFile file) {
|
| + NOTIMPLEMENTED();
|
| + return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
|
| +}
|
| +
|
| +base::PlatformFileError AsyncFileUtilTestHelper::EnsureFileExists(
|
| + FileSystemOperationContext* context,
|
| + const FileSystemURL& url,
|
| + bool* created) {
|
| + DCHECK(context);
|
| + base::PlatformFileError result;
|
| + base::RunLoop run_loop;
|
| + async_file_util_->EnsureFileExists(
|
| + context,
|
| + url,
|
| + base::Bind(&EnsureFileExistsTestCallback, &run_loop, &result, created));
|
| + run_loop.Run();
|
| + return result;
|
| +}
|
| +
|
| +base::PlatformFileError AsyncFileUtilTestHelper::CreateDirectory(
|
| + FileSystemOperationContext* context,
|
| + const FileSystemURL& url,
|
| + bool exclusive,
|
| + bool recursive) {
|
| + DCHECK(context);
|
| + base::PlatformFileError result;
|
| + base::RunLoop run_loop;
|
| + async_file_util_->CreateDirectory(context, url, exclusive, recursive,
|
| + base::Bind(&StatusTestCallback,
|
| + &run_loop, &result));
|
| + run_loop.Run();
|
| + return result;
|
| +}
|
| +
|
| +base::PlatformFileError AsyncFileUtilTestHelper::GetFileInfo(
|
| + FileSystemOperationContext* context,
|
| + const FileSystemURL& url,
|
| + base::PlatformFileInfo* file_info,
|
| + base::FilePath* platform_path) {
|
| + DCHECK(context);
|
| + base::PlatformFileError result;
|
| + base::RunLoop run_loop;
|
| + async_file_util_->GetFileInfo(
|
| + context,
|
| + url,
|
| + base::Bind(&GetFileInfoTestCallback, &run_loop, &result, file_info,
|
| + platform_path));
|
| + run_loop.Run();
|
| + return result;
|
| +}
|
| +
|
| +scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator>
|
| +AsyncFileUtilTestHelper::CreateFileEnumerator(
|
| + FileSystemOperationContext* context,
|
| + const FileSystemURL& root_url) {
|
| + NOTIMPLEMENTED();
|
| + return scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator>();
|
| +}
|
| +
|
| +base::PlatformFileError AsyncFileUtilTestHelper::GetLocalFilePath(
|
| + FileSystemOperationContext* context,
|
| + const FileSystemURL& file_system_url,
|
| + base::FilePath* local_file_path) {
|
| + NOTIMPLEMENTED();
|
| + return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
|
| +}
|
| +
|
| +base::PlatformFileError AsyncFileUtilTestHelper::Touch(
|
| + FileSystemOperationContext* context,
|
| + const FileSystemURL& url,
|
| + const base::Time& last_access_time,
|
| + const base::Time& last_modified_time) {
|
| + DCHECK(context);
|
| + base::PlatformFileError result;
|
| + base::RunLoop run_loop;
|
| + async_file_util_->Touch(context, url, last_access_time, last_modified_time,
|
| + base::Bind(&StatusTestCallback, &run_loop, &result));
|
| + run_loop.Run();
|
| + return result;
|
| +}
|
| +
|
| +base::PlatformFileError AsyncFileUtilTestHelper::Truncate(
|
| + FileSystemOperationContext* context,
|
| + const FileSystemURL& url,
|
| + int64 length) {
|
| + DCHECK(context);
|
| + base::PlatformFileError result;
|
| + base::RunLoop run_loop;
|
| + async_file_util_->Truncate(context, url, length,
|
| + base::Bind(&StatusTestCallback, &run_loop,
|
| + &result));
|
| + run_loop.Run();
|
| + return result;
|
| +}
|
| +
|
| +base::PlatformFileError AsyncFileUtilTestHelper::CopyOrMoveFile(
|
| + FileSystemOperationContext* context,
|
| + const FileSystemURL& src_url,
|
| + const FileSystemURL& dest_url,
|
| + bool copy) {
|
| + NOTIMPLEMENTED();
|
| + return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
|
| +}
|
| +
|
| +base::PlatformFileError AsyncFileUtilTestHelper::CopyInForeignFile(
|
| + FileSystemOperationContext* context,
|
| + const base::FilePath& src_file_path,
|
| + const FileSystemURL& dest_url) {
|
| + NOTIMPLEMENTED();
|
| + return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
|
| +}
|
| +
|
| +base::PlatformFileError AsyncFileUtilTestHelper::DeleteFile(
|
| + FileSystemOperationContext* context,
|
| + const FileSystemURL& url) {
|
| + NOTIMPLEMENTED();
|
| + return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
|
| +}
|
| +
|
| +base::PlatformFileError AsyncFileUtilTestHelper::DeleteDirectory(
|
| + FileSystemOperationContext* context,
|
| + const FileSystemURL& url) {
|
| + NOTIMPLEMENTED();
|
| + return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
|
| +}
|
| +
|
| +webkit_blob::ScopedFile AsyncFileUtilTestHelper::CreateSnapshotFile(
|
| + FileSystemOperationContext* context,
|
| + const FileSystemURL& url,
|
| + base::PlatformFileError* error,
|
| + base::PlatformFileInfo* file_info,
|
| + base::FilePath* platform_path) {
|
| + NOTIMPLEMENTED();
|
| + return webkit_blob::ScopedFile();
|
| +}
|
| +
|
| +base::PlatformFileError AsyncFileUtilTestHelper::ReadDirectorySync(
|
| + FileSystemOperationContext* context,
|
| + const FileSystemURL& url,
|
| + AsyncFileUtil::EntryList* file_list,
|
| + bool* has_more) {
|
| + DCHECK(context);
|
| + base::PlatformFileError result;
|
| + base::RunLoop run_loop;
|
| + async_file_util_->ReadDirectory(
|
| + context,
|
| + url,
|
| + base::Bind(&ReadDirectoryTestCallback, &run_loop, &result, file_list,
|
| + has_more));
|
| + run_loop.Run();
|
| + return result;
|
| +}
|
| +
|
| +scoped_refptr<webkit_blob::ShareableFileReference>
|
| +AsyncFileUtilTestHelper::CreateSnapshotFileSharable(
|
| + FileSystemOperationContext* context,
|
| + const FileSystemURL& url,
|
| + base::PlatformFileError* error,
|
| + base::PlatformFileInfo* file_info,
|
| + base::FilePath* platform_path) {
|
| + DCHECK(context);
|
| + scoped_refptr<webkit_blob::ShareableFileReference> file_ref_result;
|
| + CreateSnapshotResults results =
|
| + { &file_ref_result, error, file_info, platform_path };
|
| + base::RunLoop run_loop;
|
| + async_file_util_->CreateSnapshotFile(
|
| + context,
|
| + url,
|
| + base::Bind(&CreateSnapshotTestCallback, &run_loop, &results));
|
| + run_loop.Run();
|
| + return file_ref_result;
|
| +}
|
| +
|
| +} // namespace fileapi
|
|
|