This source file includes following definitions.
- TEST_F
- TEST_F
#include "chrome/browser/chromeos/drive/file_system/remove_operation.h"
#include "chrome/browser/chromeos/drive/file_system/operation_test_base.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
#include "google_apis/drive/test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace drive {
namespace file_system {
typedef OperationTestBase RemoveOperationTest;
TEST_F(RemoveOperationTest, RemoveFile) {
RemoveOperation operation(blocking_task_runner(), observer(), metadata(),
cache());
base::FilePath nonexisting_file(
FILE_PATH_LITERAL("drive/root/Dummy file.txt"));
base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
base::FilePath file_in_subdir(
FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"));
ResourceEntry entry;
FileError error = FILE_ERROR_FAILED;
ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &entry));
operation.Remove(file_in_root,
false,
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(file_in_root, &entry));
const std::string id_file_in_root = entry.local_id();
EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntryById(id_file_in_root, &entry));
EXPECT_EQ(util::kDriveTrashDirLocalId, entry.parent_local_id());
error = FILE_ERROR_FAILED;
ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_subdir, &entry));
const std::string resource_id = entry.resource_id();
operation.Remove(file_in_subdir,
false,
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
EXPECT_EQ(FILE_ERROR_NOT_FOUND,
GetLocalResourceEntry(file_in_subdir, &entry));
const std::string id_file_in_subdir = entry.local_id();
EXPECT_EQ(FILE_ERROR_OK,
GetLocalResourceEntryById(id_file_in_subdir, &entry));
EXPECT_EQ(util::kDriveTrashDirLocalId, entry.parent_local_id());
error = FILE_ERROR_FAILED;
ASSERT_EQ(FILE_ERROR_NOT_FOUND,
GetLocalResourceEntry(nonexisting_file, &entry));
operation.Remove(nonexisting_file,
false,
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
EXPECT_EQ(2U, observer()->get_changed_paths().size());
EXPECT_TRUE(observer()->get_changed_paths().count(file_in_root.DirName()));
EXPECT_TRUE(observer()->get_changed_paths().count(file_in_subdir.DirName()));
EXPECT_EQ(2U, observer()->updated_local_ids().size());
EXPECT_TRUE(observer()->updated_local_ids().count(id_file_in_root));
EXPECT_TRUE(observer()->updated_local_ids().count(id_file_in_subdir));
}
TEST_F(RemoveOperationTest, RemoveDirectory) {
RemoveOperation operation(blocking_task_runner(), observer(), metadata(),
cache());
base::FilePath empty_dir(FILE_PATH_LITERAL(
"drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder"));
base::FilePath non_empty_dir(FILE_PATH_LITERAL(
"drive/root/Directory 1"));
base::FilePath file_in_non_empty_dir(FILE_PATH_LITERAL(
"drive/root/Directory 1/SubDirectory File 1.txt"));
FileError error = FILE_ERROR_FAILED;
ResourceEntry entry;
operation.Remove(empty_dir,
false,
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
EXPECT_EQ(FILE_ERROR_NOT_FOUND,
GetLocalResourceEntry(empty_dir, &entry));
error = FILE_ERROR_FAILED;
ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(non_empty_dir, &entry));
operation.Remove(non_empty_dir,
false,
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_NOT_EMPTY, error);
EXPECT_EQ(FILE_ERROR_OK,
GetLocalResourceEntry(non_empty_dir, &entry));
error = FILE_ERROR_FAILED;
ASSERT_EQ(FILE_ERROR_OK,
GetLocalResourceEntry(file_in_non_empty_dir, &entry));
operation.Remove(non_empty_dir,
true,
google_apis::test_util::CreateCopyResultCallback(&error));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
EXPECT_EQ(FILE_ERROR_NOT_FOUND,
GetLocalResourceEntry(non_empty_dir, &entry));
EXPECT_EQ(FILE_ERROR_NOT_FOUND,
GetLocalResourceEntry(file_in_non_empty_dir, &entry));
}
}
}