This source file includes following definitions.
- TEST_F
- TEST_F
- TEST_F
#include "chrome/browser/chromeos/drive/file_system/create_file_operation.h"
#include "chrome/browser/chromeos/drive/file_system/operation_test_base.h"
#include "google_apis/drive/test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace drive {
namespace file_system {
typedef OperationTestBase CreateFileOperationTest;
TEST_F(CreateFileOperationTest, CreateFile) {
CreateFileOperation operation(blocking_task_runner(),
observer(),
metadata());
const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/New File.txt"));
FileError error = FILE_ERROR_FAILED;
operation.CreateFile(
kFilePath,
true,
std::string(),
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
ResourceEntry entry;
EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath, &entry));
EXPECT_EQ(ResourceEntry::DIRTY, entry.metadata_edit_state());
EXPECT_FALSE(base::Time::FromInternalValue(
entry.file_info().last_modified()).is_null());
EXPECT_FALSE(base::Time::FromInternalValue(
entry.file_info().last_accessed()).is_null());
EXPECT_EQ(1u, observer()->get_changed_paths().size());
EXPECT_EQ(1u, observer()->get_changed_paths().count(kFilePath.DirName()));
EXPECT_EQ(1u, observer()->updated_local_ids().size());
EXPECT_EQ(1u, observer()->updated_local_ids().count(entry.local_id()));
}
TEST_F(CreateFileOperationTest, CreateFileIsExclusive) {
CreateFileOperation operation(blocking_task_runner(),
observer(),
metadata());
const base::FilePath kExistingFile(
FILE_PATH_LITERAL("drive/root/File 1.txt"));
const base::FilePath kExistingDirectory(
FILE_PATH_LITERAL("drive/root/Directory 1"));
const base::FilePath kNonExistingFile(
FILE_PATH_LITERAL("drive/root/Directory 1/not exist.png"));
const base::FilePath kFileInNonExistingDirectory(
FILE_PATH_LITERAL("drive/root/not exist/not exist.png"));
FileError error = FILE_ERROR_FAILED;
operation.CreateFile(
kExistingFile,
true,
std::string(),
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_EXISTS, error);
operation.CreateFile(
kExistingFile,
false,
std::string(),
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
operation.CreateFile(
kExistingDirectory,
false,
std::string(),
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_EXISTS, error);
operation.CreateFile(
kNonExistingFile,
true,
std::string(),
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
operation.CreateFile(
kFileInNonExistingDirectory,
false,
std::string(),
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error);
}
TEST_F(CreateFileOperationTest, CreateFileMimeType) {
CreateFileOperation operation(blocking_task_runner(),
observer(),
metadata());
const base::FilePath kPng1(FILE_PATH_LITERAL("drive/root/1.png"));
const base::FilePath kPng2(FILE_PATH_LITERAL("drive/root/2.png"));
const base::FilePath kUnknown(FILE_PATH_LITERAL("drive/root/3.unknown"));
const std::string kSpecialMimeType("application/x-createfile-test");
FileError error = FILE_ERROR_FAILED;
operation.CreateFile(
kPng1,
false,
std::string(),
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
ResourceEntry entry;
ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPng1, &entry));
EXPECT_EQ("image/png", entry.file_specific_info().content_mime_type());
error = FILE_ERROR_FAILED;
operation.CreateFile(
kPng2,
false,
kSpecialMimeType,
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPng2, &entry));
EXPECT_EQ(kSpecialMimeType, entry.file_specific_info().content_mime_type());
error = FILE_ERROR_FAILED;
operation.CreateFile(
kUnknown,
false,
std::string(),
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kUnknown, &entry));
EXPECT_EQ("application/octet-stream",
entry.file_specific_info().content_mime_type());
}
}
}