#include <string>
-#include "base/file_util.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
+#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/message_loop/message_loop_proxy.h"
-#include "base/platform_file.h"
#include "base/run_loop.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/test/async_file_test_helper.h"
#include "content/public/test/test_file_system_context.h"
+#include "storage/browser/fileapi/async_file_util_adapter.h"
+#include "storage/browser/fileapi/file_system_context.h"
+#include "storage/browser/fileapi/file_system_file_util.h"
+#include "storage/browser/fileapi/file_system_operation_context.h"
+#include "storage/browser/fileapi/local_file_util.h"
+#include "storage/browser/fileapi/native_file_util.h"
+#include "storage/common/fileapi/file_system_types.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "webkit/browser/fileapi/async_file_util_adapter.h"
-#include "webkit/browser/fileapi/file_system_context.h"
-#include "webkit/browser/fileapi/file_system_file_util.h"
-#include "webkit/browser/fileapi/file_system_operation_context.h"
-#include "webkit/browser/fileapi/local_file_util.h"
-#include "webkit/browser/fileapi/native_file_util.h"
-#include "webkit/common/fileapi/file_system_types.h"
using content::AsyncFileTestHelper;
-using fileapi::AsyncFileUtilAdapter;
-using fileapi::FileSystemContext;
-using fileapi::FileSystemOperationContext;
-using fileapi::FileSystemType;
-using fileapi::FileSystemURL;
-using fileapi::LocalFileUtil;
+using storage::AsyncFileUtilAdapter;
+using storage::FileSystemContext;
+using storage::FileSystemOperationContext;
+using storage::FileSystemURL;
+using storage::LocalFileUtil;
namespace content {
namespace {
const GURL kOrigin("http://foo/");
-const FileSystemType kFileSystemType = fileapi::kFileSystemTypeTest;
+const storage::FileSystemType kFileSystemType = storage::kFileSystemTypeTest;
} // namespace
public:
LocalFileUtilTest() {}
- virtual void SetUp() {
+ void SetUp() override {
ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
file_system_context_ = CreateFileSystemContextForTesting(
NULL, data_dir_.path());
}
- virtual void TearDown() {
+ void TearDown() override {
file_system_context_ = NULL;
base::RunLoop().RunUntilIdle();
}
return info.size;
}
- base::File::Error CreateFile(const char* file_name,
- base::PlatformFile* file_handle,
- bool* created) {
- int file_flags = base::PLATFORM_FILE_CREATE |
- base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC;
+ base::File CreateFile(const char* file_name) {
+ int file_flags = base::File::FLAG_CREATE |
+ base::File::FLAG_WRITE | base::File::FLAG_ASYNC;
scoped_ptr<FileSystemOperationContext> context(NewContext());
- return file_util()->CreateOrOpen(
- context.get(),
- CreateURL(file_name),
- file_flags, file_handle, created);
+ return file_util()->CreateOrOpen(context.get(), CreateURL(file_name),
+ file_flags);
}
base::File::Error EnsureFileExists(const char* file_name,
- bool* created) {
+ bool* created) {
scoped_ptr<FileSystemOperationContext> context(NewContext());
- return file_util()->EnsureFileExists(
- context.get(),
- CreateURL(file_name), created);
+ return file_util()->EnsureFileExists(context.get(),
+ CreateURL(file_name), created);
}
FileSystemContext* file_system_context() {
TEST_F(LocalFileUtilTest, CreateAndClose) {
const char *file_name = "test_file";
- base::PlatformFile file_handle;
- bool created;
- ASSERT_EQ(base::File::FILE_OK,
- CreateFile(file_name, &file_handle, &created));
- ASSERT_TRUE(created);
+ base::File file = CreateFile(file_name);
+ ASSERT_TRUE(file.IsValid());
+ ASSERT_TRUE(file.created());
EXPECT_TRUE(FileExists(file_name));
EXPECT_EQ(0, GetSize(file_name));
scoped_ptr<FileSystemOperationContext> context(NewContext());
- EXPECT_EQ(base::File::FILE_OK,
- file_util()->Close(context.get(), file_handle));
}
// base::CreateSymbolicLink is only supported on POSIX.
TEST_F(LocalFileUtilTest, CreateFailForSymlink) {
// Create symlink target file.
const char *target_name = "symlink_target";
- base::PlatformFile target_handle;
- bool symlink_target_created = false;
- ASSERT_EQ(base::File::FILE_OK,
- CreateFile(target_name, &target_handle, &symlink_target_created));
- ASSERT_TRUE(symlink_target_created);
+ base::File target_file = CreateFile(target_name);
+ ASSERT_TRUE(target_file.IsValid());
+ ASSERT_TRUE(target_file.created());
base::FilePath target_path = LocalPath(target_name);
// Create symlink where target must be real file.
// Try to open the symlink file which should fail.
scoped_ptr<FileSystemOperationContext> context(NewContext());
FileSystemURL url = CreateURL(symlink_name);
- int file_flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
- base::PlatformFile file_handle;
- bool created = false;
- EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND,
- file_util()->CreateOrOpen(context.get(), url, file_flags,
- &file_handle, &created));
- EXPECT_FALSE(created);
+ int file_flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
+ base::File file = file_util()->CreateOrOpen(context.get(), url, file_flags);
+ ASSERT_FALSE(file.IsValid());
+ EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, file.error_details());
}
#endif
TEST_F(LocalFileUtilTest, TouchFile) {
const char *file_name = "test_file";
- base::PlatformFile file_handle;
- bool created;
- ASSERT_EQ(base::File::FILE_OK,
- CreateFile(file_name, &file_handle, &created));
- ASSERT_TRUE(created);
+ base::File file = CreateFile(file_name);
+ ASSERT_TRUE(file.IsValid());
+ ASSERT_TRUE(file.created());
scoped_ptr<FileSystemOperationContext> context(NewContext());
ASSERT_TRUE(base::GetFileInfo(LocalPath(file_name), &info));
EXPECT_EQ(new_accessed, info.last_accessed);
EXPECT_EQ(new_modified, info.last_modified);
-
- EXPECT_EQ(base::File::FILE_OK,
- file_util()->Close(context.get(), file_handle));
}
TEST_F(LocalFileUtilTest, TouchDirectory) {