This source file includes following definitions.
- FindDirectory
- TEST_F
#include "chrome/browser/chromeos/drive/file_system/create_directory_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 {
class CreateDirectoryOperationTest : public OperationTestBase {
protected:
FileError FindDirectory(const base::FilePath& path) {
ResourceEntry entry;
FileError error = GetLocalResourceEntry(path, &entry);
if (error == FILE_ERROR_OK && !entry.file_info().is_directory())
error = FILE_ERROR_NOT_A_DIRECTORY;
return error;
}
};
TEST_F(CreateDirectoryOperationTest, CreateDirectory) {
CreateDirectoryOperation 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 kNewDirectory1(
FILE_PATH_LITERAL("drive/root/New Directory"));
const base::FilePath kNewDirectory2 =
kNewDirectory1.AppendASCII("New Directory 2/a/b/c");
EXPECT_EQ(FILE_ERROR_NOT_FOUND, FindDirectory(kNewDirectory1));
FileError error = FILE_ERROR_FAILED;
operation.CreateDirectory(
kNewDirectory1,
true,
false,
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
EXPECT_EQ(FILE_ERROR_OK, FindDirectory(kNewDirectory1));
EXPECT_EQ(1U, observer()->get_changed_paths().size());
EXPECT_EQ(1U,
observer()->get_changed_paths().count(kNewDirectory1.DirName()));
ResourceEntry entry;
EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kNewDirectory1, &entry));
EXPECT_EQ(ResourceEntry::DIRTY, entry.metadata_edit_state());
EXPECT_TRUE(entry.file_info().is_directory());
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()->updated_local_ids().size());
EXPECT_EQ(1U, observer()->updated_local_ids().count(entry.local_id()));
EXPECT_EQ(FILE_ERROR_NOT_FOUND, FindDirectory(kNewDirectory2));
operation.CreateDirectory(
kNewDirectory2,
true,
false,
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
EXPECT_EQ(FILE_ERROR_NOT_FOUND, FindDirectory(kNewDirectory2));
operation.CreateDirectory(
kNewDirectory2,
true,
true,
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
EXPECT_EQ(FILE_ERROR_OK, FindDirectory(kNewDirectory2));
operation.CreateDirectory(
kExistingDirectory,
true,
false,
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_EXISTS, error);
operation.CreateDirectory(
kExistingDirectory,
false,
false,
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
operation.CreateDirectory(
kExistingFile,
false,
true,
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error);
operation.CreateDirectory(
kExistingFile.AppendASCII("New Directory"),
false,
true,
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error);
}
}
}