diff options
author | pilgrim@chromium.org <pilgrim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-13 17:12:19 +0000 |
---|---|---|
committer | pilgrim@chromium.org <pilgrim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-13 17:12:19 +0000 |
commit | 1dbc79338567e4311cfa458357ca30cfa1080d1f (patch) | |
tree | 2fed43c694f0224e42d6fedbb1c23e90c1aa8eae /webkit | |
parent | 95522e595aa6e4978aaa07483f02faab93372b82 (diff) | |
download | chromium_src-1dbc79338567e4311cfa458357ca30cfa1080d1f.zip chromium_src-1dbc79338567e4311cfa458357ca30cfa1080d1f.tar.gz chromium_src-1dbc79338567e4311cfa458357ca30cfa1080d1f.tar.bz2 |
Move async_file_test_helper.* to content/public/test/
BUG=338338
Review URL: https://codereview.chromium.org/157053010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251069 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/browser/fileapi/async_file_test_helper.cc | 270 | ||||
-rw-r--r-- | webkit/browser/fileapi/async_file_test_helper.h | 109 |
2 files changed, 0 insertions, 379 deletions
diff --git a/webkit/browser/fileapi/async_file_test_helper.cc b/webkit/browser/fileapi/async_file_test_helper.cc deleted file mode 100644 index 0e88298..0000000 --- a/webkit/browser/fileapi/async_file_test_helper.cc +++ /dev/null @@ -1,270 +0,0 @@ -// Copyright (c) 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 "base/bind.h" -#include "base/file_util.h" -#include "base/files/scoped_temp_dir.h" -#include "base/run_loop.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "webkit/browser/fileapi/async_file_test_helper.h" -#include "webkit/browser/fileapi/file_system_backend.h" -#include "webkit/browser/fileapi/file_system_context.h" -#include "webkit/browser/fileapi/file_system_operation_runner.h" -#include "webkit/browser/fileapi/file_system_url.h" -#include "webkit/browser/quota/quota_manager.h" -#include "webkit/common/fileapi/file_system_util.h" - -namespace fileapi { - -namespace { - -typedef FileSystemOperation::FileEntryList FileEntryList; - -void AssignAndQuit(base::RunLoop* run_loop, - base::File::Error* result_out, - base::File::Error result) { - *result_out = result; - run_loop->Quit(); -} - -base::Callback<void(base::File::Error)> -AssignAndQuitCallback(base::RunLoop* run_loop, - base::File::Error* result) { - return base::Bind(&AssignAndQuit, run_loop, base::Unretained(result)); -} - -void GetMetadataCallback(base::RunLoop* run_loop, - base::File::Error* result_out, - base::File::Info* file_info_out, - base::File::Error result, - const base::File::Info& file_info) { - *result_out = result; - if (file_info_out) - *file_info_out = file_info; - run_loop->Quit(); -} - -void CreateSnapshotFileCallback( - base::RunLoop* run_loop, - base::File::Error* result_out, - base::FilePath* platform_path_out, - base::File::Error result, - const base::File::Info& file_info, - const base::FilePath& platform_path, - const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { - DCHECK(!file_ref.get()); - *result_out = result; - if (platform_path_out) - *platform_path_out = platform_path; - run_loop->Quit(); -} - -void ReadDirectoryCallback(base::RunLoop* run_loop, - base::File::Error* result_out, - FileEntryList* entries_out, - base::File::Error result, - const FileEntryList& entries, - bool has_more) { - *result_out = result; - *entries_out = entries; - if (result != base::File::FILE_OK || !has_more) - run_loop->Quit(); -} - -void DidGetUsageAndQuota(quota::QuotaStatusCode* status_out, - int64* usage_out, - int64* quota_out, - quota::QuotaStatusCode status, - int64 usage, - int64 quota) { - if (status_out) - *status_out = status; - if (usage_out) - *usage_out = usage; - if (quota_out) - *quota_out = quota; -} - -} // namespace - -const int64 AsyncFileTestHelper::kDontCheckSize = -1; - -base::File::Error AsyncFileTestHelper::Copy( - FileSystemContext* context, - const FileSystemURL& src, - const FileSystemURL& dest) { - return CopyWithProgress(context, src, dest, CopyProgressCallback()); -} - -base::File::Error AsyncFileTestHelper::CopyWithProgress( - FileSystemContext* context, - const FileSystemURL& src, - const FileSystemURL& dest, - const CopyProgressCallback& progress_callback) { - base::File::Error result = base::File::FILE_ERROR_FAILED; - base::RunLoop run_loop; - context->operation_runner()->Copy( - src, dest, FileSystemOperation::OPTION_NONE, progress_callback, - AssignAndQuitCallback(&run_loop, &result)); - run_loop.Run(); - return result; -} - -base::File::Error AsyncFileTestHelper::Move( - FileSystemContext* context, - const FileSystemURL& src, - const FileSystemURL& dest) { - base::File::Error result = base::File::FILE_ERROR_FAILED; - base::RunLoop run_loop; - context->operation_runner()->Move( - src, dest, FileSystemOperation::OPTION_NONE, - AssignAndQuitCallback(&run_loop, &result)); - run_loop.Run(); - return result; -} - -base::File::Error AsyncFileTestHelper::Remove( - FileSystemContext* context, - const FileSystemURL& url, - bool recursive) { - base::File::Error result = base::File::FILE_ERROR_FAILED; - base::RunLoop run_loop; - context->operation_runner()->Remove( - url, recursive, AssignAndQuitCallback(&run_loop, &result)); - run_loop.Run(); - return result; -} - -base::File::Error AsyncFileTestHelper::ReadDirectory( - FileSystemContext* context, - const FileSystemURL& url, - FileEntryList* entries) { - base::File::Error result = base::File::FILE_ERROR_FAILED; - DCHECK(entries); - entries->clear(); - base::RunLoop run_loop; - context->operation_runner()->ReadDirectory( - url, base::Bind(&ReadDirectoryCallback, &run_loop, &result, entries)); - run_loop.Run(); - return result; -} - -base::File::Error AsyncFileTestHelper::CreateDirectory( - FileSystemContext* context, - const FileSystemURL& url) { - base::File::Error result = base::File::FILE_ERROR_FAILED; - base::RunLoop run_loop; - context->operation_runner()->CreateDirectory( - url, - false /* exclusive */, - false /* recursive */, - AssignAndQuitCallback(&run_loop, &result)); - run_loop.Run(); - return result; -} - -base::File::Error AsyncFileTestHelper::CreateFile( - FileSystemContext* context, - const FileSystemURL& url) { - base::File::Error result = base::File::FILE_ERROR_FAILED; - base::RunLoop run_loop; - context->operation_runner()->CreateFile( - url, false /* exclusive */, - AssignAndQuitCallback(&run_loop, &result)); - run_loop.Run(); - return result; -} - -base::File::Error AsyncFileTestHelper::CreateFileWithData( - FileSystemContext* context, - const FileSystemURL& url, - const char* buf, - int buf_size) { - base::ScopedTempDir dir; - if (!dir.CreateUniqueTempDir()) - return base::File::FILE_ERROR_FAILED; - base::FilePath local_path = dir.path().AppendASCII("tmp"); - if (buf_size != file_util::WriteFile(local_path, buf, buf_size)) - return base::File::FILE_ERROR_FAILED; - base::File::Error result = base::File::FILE_ERROR_FAILED; - base::RunLoop run_loop; - context->operation_runner()->CopyInForeignFile( - local_path, url, AssignAndQuitCallback(&run_loop, &result)); - run_loop.Run(); - return result; -} - -base::File::Error AsyncFileTestHelper::TruncateFile( - FileSystemContext* context, - const FileSystemURL& url, - size_t size) { - base::RunLoop run_loop; - base::File::Error result = base::File::FILE_ERROR_FAILED; - context->operation_runner()->Truncate( - url, size, AssignAndQuitCallback(&run_loop, &result)); - run_loop.Run(); - return result; -} - -base::File::Error AsyncFileTestHelper::GetMetadata( - FileSystemContext* context, - const FileSystemURL& url, - base::File::Info* file_info) { - base::File::Error result = base::File::FILE_ERROR_FAILED; - base::RunLoop run_loop; - context->operation_runner()->GetMetadata( - url, base::Bind(&GetMetadataCallback, &run_loop, &result, - file_info)); - run_loop.Run(); - return result; -} - -base::File::Error AsyncFileTestHelper::GetPlatformPath( - FileSystemContext* context, - const FileSystemURL& url, - base::FilePath* platform_path) { - base::File::Error result = base::File::FILE_ERROR_FAILED; - base::RunLoop run_loop; - context->operation_runner()->CreateSnapshotFile( - url, base::Bind(&CreateSnapshotFileCallback, &run_loop, &result, - platform_path)); - run_loop.Run(); - return result; -} - -bool AsyncFileTestHelper::FileExists( - FileSystemContext* context, - const FileSystemURL& url, - int64 expected_size) { - base::File::Info file_info; - base::File::Error result = GetMetadata(context, url, &file_info); - if (result != base::File::FILE_OK || file_info.is_directory) - return false; - return expected_size == kDontCheckSize || file_info.size == expected_size; -} - -bool AsyncFileTestHelper::DirectoryExists( - FileSystemContext* context, - const FileSystemURL& url) { - base::File::Info file_info; - base::File::Error result = GetMetadata(context, url, &file_info); - return (result == base::File::FILE_OK) && file_info.is_directory; -} - -quota::QuotaStatusCode AsyncFileTestHelper::GetUsageAndQuota( - quota::QuotaManager* quota_manager, - const GURL& origin, - FileSystemType type, - int64* usage, - int64* quota) { - quota::QuotaStatusCode status = quota::kQuotaStatusUnknown; - quota_manager->GetUsageAndQuota( - origin, - FileSystemTypeToQuotaStorageType(type), - base::Bind(&DidGetUsageAndQuota, &status, usage, quota)); - base::RunLoop().RunUntilIdle(); - return status; -} - -} // namespace fileapi diff --git a/webkit/browser/fileapi/async_file_test_helper.h b/webkit/browser/fileapi/async_file_test_helper.h deleted file mode 100644 index fc2c95e..0000000 --- a/webkit/browser/fileapi/async_file_test_helper.h +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (c) 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. - -#ifndef WEBKIT_BROWSER_FILEAPI_ASYNC_FILE_TEST_HELPER_H_ -#define WEBKIT_BROWSER_FILEAPI_ASYNC_FILE_TEST_HELPER_H_ - -#include "base/basictypes.h" -#include "webkit/browser/fileapi/file_system_operation.h" -#include "webkit/common/fileapi/file_system_types.h" -#include "webkit/common/quota/quota_status_code.h" - -namespace quota { -class QuotaManager; -} - -namespace fileapi { - -class FileSystemContext; -class FileSystemURL; - -// A helper class to perform async file operations in a synchronous way. -class AsyncFileTestHelper { - public: - typedef FileSystemOperation::FileEntryList FileEntryList; - typedef FileSystemOperation::CopyProgressCallback CopyProgressCallback; - - static const int64 kDontCheckSize; - - // Performs Copy from |src| to |dest| and returns the status code. - static base::File::Error Copy(FileSystemContext* context, - const FileSystemURL& src, - const FileSystemURL& dest); - - // Same as Copy, but this supports |progress_callback|. - static base::File::Error CopyWithProgress( - FileSystemContext* context, - const FileSystemURL& src, - const FileSystemURL& dest, - const CopyProgressCallback& progress_callback); - - // Performs Move from |src| to |dest| and returns the status code. - static base::File::Error Move(FileSystemContext* context, - const FileSystemURL& src, - const FileSystemURL& dest); - - // Removes the given |url|. - static base::File::Error Remove(FileSystemContext* context, - const FileSystemURL& url, - bool recursive); - - // Performs ReadDirectory on |url|. - static base::File::Error ReadDirectory(FileSystemContext* context, - const FileSystemURL& url, - FileEntryList* entries); - - // Creates a directory at |url|. - static base::File::Error CreateDirectory(FileSystemContext* context, - const FileSystemURL& url); - - // Creates a file at |url|. - static base::File::Error CreateFile(FileSystemContext* context, - const FileSystemURL& url); - - // Creates a file at |url| and fills with |buf|. - static base::File::Error CreateFileWithData( - FileSystemContext* context, - const FileSystemURL& url, - const char* buf, - int buf_size); - - // Truncates the file |url| to |size|. - static base::File::Error TruncateFile(FileSystemContext* context, - const FileSystemURL& url, - size_t size); - - // Retrieves File::Info for |url| and populates |file_info|. - static base::File::Error GetMetadata(FileSystemContext* context, - const FileSystemURL& url, - base::File::Info* file_info); - - // Retrieves FilePath for |url| and populates |platform_path|. - static base::File::Error GetPlatformPath(FileSystemContext* context, - const FileSystemURL& url, - base::FilePath* platform_path); - - // Returns true if a file exists at |url| with |size|. If |size| is - // kDontCheckSize it doesn't check the file size (but just check its - // existence). - static bool FileExists(FileSystemContext* context, - const FileSystemURL& url, - int64 size); - - // Returns true if a directory exists at |url|. - static bool DirectoryExists(FileSystemContext* context, - const FileSystemURL& url); - - // Returns usage and quota. It's valid to pass NULL to |usage| and/or |quota|. - static quota::QuotaStatusCode GetUsageAndQuota( - quota::QuotaManager* quota_manager, - const GURL& origin, - FileSystemType type, - int64* usage, - int64* quota); -}; - -} // namespace fileapi - -#endif // WEBKIT_BROWSER_FILEAPI_ASYNC_FILE_TEST_HELPER_H_ |