This source file includes following definitions.
- GetSortedBaseNames
- CreateDirectoryEntryWithResourceId
- CreateDirectoryEntry
- CreateFileEntryWithResourceId
- CreateFileEntry
- SetUpEntries
- SetUp
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "chrome/browser/chromeos/drive/resource_metadata.h"
#include <algorithm>
#include <string>
#include <vector>
#include "base/files/scoped_temp_dir.h"
#include "chrome/browser/chromeos/drive/drive.pb.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/drive/test_util.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace drive {
namespace internal {
namespace {
const int64 kTestChangestamp = 100;
std::vector<std::string> GetSortedBaseNames(
const ResourceEntryVector& entries) {
std::vector<std::string> base_names;
for (size_t i = 0; i < entries.size(); ++i)
base_names.push_back(entries[i].base_name());
std::sort(base_names.begin(), base_names.end());
return base_names;
}
ResourceEntry CreateDirectoryEntryWithResourceId(
const std::string& title,
const std::string& resource_id,
const std::string& parent_local_id) {
ResourceEntry entry;
entry.set_title(title);
entry.set_resource_id(resource_id);
entry.set_parent_local_id(parent_local_id);
entry.mutable_file_info()->set_is_directory(true);
entry.mutable_directory_specific_info()->set_changestamp(kTestChangestamp);
return entry;
}
ResourceEntry CreateDirectoryEntry(const std::string& title,
const std::string& parent_local_id) {
return CreateDirectoryEntryWithResourceId(
title, "id:" + title, parent_local_id);
}
ResourceEntry CreateFileEntryWithResourceId(
const std::string& title,
const std::string& resource_id,
const std::string& parent_local_id) {
ResourceEntry entry;
entry.set_title(title);
entry.set_resource_id(resource_id);
entry.set_parent_local_id(parent_local_id);
entry.mutable_file_info()->set_is_directory(false);
entry.mutable_file_info()->set_size(1024);
entry.mutable_file_specific_info()->set_md5("md5:" + title);
return entry;
}
ResourceEntry CreateFileEntry(const std::string& title,
const std::string& parent_local_id) {
return CreateFileEntryWithResourceId(title, "id:" + title, parent_local_id);
}
void SetUpEntries(ResourceMetadata* resource_metadata) {
std::string local_id;
ASSERT_EQ(FILE_ERROR_OK, resource_metadata->GetIdByPath(
util::GetDriveMyDriveRootPath(), &local_id));
const std::string root_local_id = local_id;
ASSERT_EQ(FILE_ERROR_OK, resource_metadata->AddEntry(
CreateDirectoryEntry("dir1", root_local_id), &local_id));
const std::string local_id_dir1 = local_id;
ASSERT_EQ(FILE_ERROR_OK, resource_metadata->AddEntry(
CreateDirectoryEntry("dir2", root_local_id), &local_id));
const std::string local_id_dir2 = local_id;
ASSERT_EQ(FILE_ERROR_OK, resource_metadata->AddEntry(
CreateDirectoryEntry("dir3", local_id_dir1), &local_id));
const std::string local_id_dir3 = local_id;
ASSERT_EQ(FILE_ERROR_OK, resource_metadata->AddEntry(
CreateFileEntry("file4", local_id_dir1), &local_id));
ASSERT_EQ(FILE_ERROR_OK, resource_metadata->AddEntry(
CreateFileEntry("file5", local_id_dir1), &local_id));
ASSERT_EQ(FILE_ERROR_OK, resource_metadata->AddEntry(
CreateFileEntry("file6", local_id_dir2), &local_id));
ASSERT_EQ(FILE_ERROR_OK, resource_metadata->AddEntry(
CreateFileEntry("file7", local_id_dir2), &local_id));
ASSERT_EQ(FILE_ERROR_OK, resource_metadata->AddEntry(
CreateFileEntry("file8", local_id_dir2), &local_id));
ASSERT_EQ(FILE_ERROR_OK, resource_metadata->AddEntry(
CreateFileEntry("file9", local_id_dir3), &local_id));
ASSERT_EQ(FILE_ERROR_OK, resource_metadata->AddEntry(
CreateFileEntry("file10", local_id_dir3), &local_id));
ASSERT_EQ(FILE_ERROR_OK,
resource_metadata->SetLargestChangestamp(kTestChangestamp));
}
}
class ResourceMetadataTest : public testing::Test {
protected:
virtual void SetUp() OVERRIDE {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
metadata_storage_.reset(new ResourceMetadataStorage(
temp_dir_.path(), base::MessageLoopProxy::current().get()));
ASSERT_TRUE(metadata_storage_->Initialize());
resource_metadata_.reset(new ResourceMetadata(
metadata_storage_.get(), base::MessageLoopProxy::current()));
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->Initialize());
SetUpEntries(resource_metadata_.get());
}
base::ScopedTempDir temp_dir_;
content::TestBrowserThreadBundle thread_bundle_;
scoped_ptr<ResourceMetadataStorage, test_util::DestroyHelperForTests>
metadata_storage_;
scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests>
resource_metadata_;
};
TEST_F(ResourceMetadataTest, LargestChangestamp) {
const int64 kChangestamp = 123456;
EXPECT_EQ(FILE_ERROR_OK,
resource_metadata_->SetLargestChangestamp(kChangestamp));
EXPECT_EQ(kChangestamp, resource_metadata_->GetLargestChangestamp());
}
TEST_F(ResourceMetadataTest, GetResourceEntryByPath) {
ResourceEntry entry;
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryByPath(
base::FilePath::FromUTF8Unsafe("drive/root/dir1/file4"), &entry));
EXPECT_EQ("file4", entry.base_name());
EXPECT_EQ(FILE_ERROR_NOT_FOUND, resource_metadata_->GetResourceEntryByPath(
base::FilePath::FromUTF8Unsafe("drive/root/dir1/non_existing"), &entry));
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryByPath(
base::FilePath::FromUTF8Unsafe("drive"), &entry));
EXPECT_EQ(FILE_ERROR_NOT_FOUND, resource_metadata_->GetResourceEntryByPath(
base::FilePath::FromUTF8Unsafe("non_existing"), &entry));
EXPECT_EQ(FILE_ERROR_NOT_FOUND, resource_metadata_->GetResourceEntryByPath(
base::FilePath::FromUTF8Unsafe("non_existing/root"), &entry));
}
TEST_F(ResourceMetadataTest, ReadDirectoryByPath) {
ResourceEntryVector entries;
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->ReadDirectoryByPath(
base::FilePath::FromUTF8Unsafe("drive/root/dir1"), &entries));
ASSERT_EQ(3U, entries.size());
std::vector<std::string> base_names = GetSortedBaseNames(entries);
EXPECT_EQ("dir3", base_names[0]);
EXPECT_EQ("file4", base_names[1]);
EXPECT_EQ("file5", base_names[2]);
EXPECT_EQ(FILE_ERROR_NOT_FOUND, resource_metadata_->ReadDirectoryByPath(
base::FilePath::FromUTF8Unsafe("drive/root/non_existing"), &entries));
EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, resource_metadata_->ReadDirectoryByPath(
base::FilePath::FromUTF8Unsafe("drive/root/dir1/file4"), &entries));
}
TEST_F(ResourceMetadataTest, RefreshEntry) {
base::FilePath drive_file_path;
ResourceEntry entry;
std::string file_id;
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetIdByPath(
base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3/file9"), &file_id));
EXPECT_EQ(FILE_ERROR_OK,
resource_metadata_->GetResourceEntryById(file_id, &entry));
EXPECT_EQ("file9", entry.base_name());
EXPECT_TRUE(!entry.file_info().is_directory());
EXPECT_EQ("md5:file9", entry.file_specific_info().md5());
ResourceEntry file_entry(entry);
file_entry.set_title("file100");
EXPECT_EQ(FILE_ERROR_OK,
resource_metadata_->RefreshEntry(file_entry));
EXPECT_EQ("drive/root/dir1/dir3/file100",
resource_metadata_->GetFilePath(file_id).AsUTF8Unsafe());
entry.Clear();
EXPECT_EQ(FILE_ERROR_OK,
resource_metadata_->GetResourceEntryById(file_id, &entry));
EXPECT_EQ("file100", entry.base_name());
EXPECT_TRUE(!entry.file_info().is_directory());
EXPECT_EQ("md5:file9", entry.file_specific_info().md5());
const std::string updated_md5("md5:updated");
file_entry = entry;
file_entry.mutable_file_specific_info()->set_md5(updated_md5);
EXPECT_EQ(FILE_ERROR_OK,
resource_metadata_->RefreshEntry(file_entry));
EXPECT_EQ("drive/root/dir1/dir3/file100",
resource_metadata_->GetFilePath(file_id).AsUTF8Unsafe());
entry.Clear();
EXPECT_EQ(FILE_ERROR_OK,
resource_metadata_->GetResourceEntryById(file_id, &entry));
EXPECT_EQ("file100", entry.base_name());
EXPECT_TRUE(!entry.file_info().is_directory());
EXPECT_EQ(updated_md5, entry.file_specific_info().md5());
entry.Clear();
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryByPath(
base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3/file100"), &entry));
EXPECT_EQ("file100", entry.base_name());
ASSERT_TRUE(!entry.file_info().is_directory());
EXPECT_EQ(updated_md5, entry.file_specific_info().md5());
entry.Clear();
std::string dir_id;
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetIdByPath(
base::FilePath::FromUTF8Unsafe("drive/root/dir2"), &dir_id));
EXPECT_EQ(FILE_ERROR_OK,
resource_metadata_->GetResourceEntryById(dir_id, &entry));
EXPECT_EQ("dir2", entry.base_name());
ASSERT_TRUE(entry.file_info().is_directory());
std::string dir3_id;
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetIdByPath(
base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3"), &dir3_id));
ResourceEntry dir_entry(entry);
dir_entry.set_title("dir100");
dir_entry.set_parent_local_id(dir3_id);
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->RefreshEntry(dir_entry));
EXPECT_EQ("drive/root/dir1/dir3/dir100",
resource_metadata_->GetFilePath(dir_id).AsUTF8Unsafe());
entry.Clear();
EXPECT_EQ(FILE_ERROR_OK,
resource_metadata_->GetResourceEntryById(dir_id, &entry));
EXPECT_EQ("dir100", entry.base_name());
EXPECT_TRUE(entry.file_info().is_directory());
EXPECT_EQ("id:dir2", entry.resource_id());
entry.Clear();
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryByPath(
base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3/dir100/file6"),
&entry));
EXPECT_EQ("file6", entry.base_name());
EXPECT_EQ(FILE_ERROR_NOT_FOUND, resource_metadata_->GetResourceEntryByPath(
base::FilePath::FromUTF8Unsafe("drive/root/dir2"), &entry));
dir_entry.set_parent_local_id(file_id);
EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY,
resource_metadata_->RefreshEntry(dir_entry));
dir_entry.Clear();
dir_entry.set_local_id(util::kDriveGrandRootLocalId);
dir_entry.set_title("new-root-name");
dir_entry.set_parent_local_id(dir3_id);
EXPECT_EQ(FILE_ERROR_INVALID_OPERATION,
resource_metadata_->RefreshEntry(dir_entry));
}
TEST_F(ResourceMetadataTest, RefreshEntry_ResourceIDCheck) {
ResourceEntry entry;
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryByPath(
base::FilePath::FromUTF8Unsafe("drive/root/dir1"), &entry));
EXPECT_FALSE(entry.resource_id().empty());
ResourceEntry new_entry;
new_entry.set_parent_local_id(entry.local_id());
new_entry.set_title("new entry");
std::string local_id;
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(new_entry, &local_id));
new_entry.set_local_id(local_id);
new_entry.set_resource_id(entry.resource_id());
EXPECT_EQ(FILE_ERROR_INVALID_OPERATION,
resource_metadata_->RefreshEntry(new_entry));
}
TEST_F(ResourceMetadataTest, GetSubDirectoriesRecursively) {
std::set<base::FilePath> sub_directories;
std::string local_id;
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetIdByPath(
base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3/file9"), &local_id));
resource_metadata_->GetSubDirectoriesRecursively(local_id, &sub_directories);
EXPECT_TRUE(sub_directories.empty());
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetIdByPath(
base::FilePath::FromUTF8Unsafe("drive/root/dir2"), &local_id));
resource_metadata_->GetSubDirectoriesRecursively(local_id, &sub_directories);
EXPECT_TRUE(sub_directories.empty());
const std::string dir2_id = local_id;
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetIdByPath(
base::FilePath::FromUTF8Unsafe("drive/root/dir1"), &local_id));
resource_metadata_->GetSubDirectoriesRecursively(local_id, &sub_directories);
EXPECT_EQ(1u, sub_directories.size());
EXPECT_EQ(1u, sub_directories.count(
base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3")));
sub_directories.clear();
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(
CreateDirectoryEntry("dir100", dir2_id), &local_id));
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(
CreateDirectoryEntry("dir101", dir2_id), &local_id));
const std::string dir101_id = local_id;
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(
CreateDirectoryEntry("dir102", dir101_id), &local_id));
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(
CreateDirectoryEntry("dir103", dir101_id), &local_id));
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(
CreateDirectoryEntry("dir104", dir101_id), &local_id));
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(
CreateDirectoryEntry("dir105", local_id), &local_id));
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(
CreateDirectoryEntry("dir106", local_id), &local_id));
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(
CreateDirectoryEntry("dir107", local_id), &local_id));
resource_metadata_->GetSubDirectoriesRecursively(dir2_id, &sub_directories);
EXPECT_EQ(8u, sub_directories.size());
EXPECT_EQ(1u, sub_directories.count(base::FilePath::FromUTF8Unsafe(
"drive/root/dir2/dir101")));
EXPECT_EQ(1u, sub_directories.count(base::FilePath::FromUTF8Unsafe(
"drive/root/dir2/dir101/dir104")));
EXPECT_EQ(1u, sub_directories.count(base::FilePath::FromUTF8Unsafe(
"drive/root/dir2/dir101/dir104/dir105/dir106/dir107")));
}
TEST_F(ResourceMetadataTest, AddEntry) {
base::FilePath drive_file_path;
std::string local_id;
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetIdByPath(
base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3"), &local_id));
ResourceEntry file_entry = CreateFileEntry("file100", local_id);
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(file_entry, &local_id));
EXPECT_EQ("drive/root/dir1/dir3/file100",
resource_metadata_->GetFilePath(local_id).AsUTF8Unsafe());
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetIdByPath(
base::FilePath::FromUTF8Unsafe("drive/root/dir1"), &local_id));
ResourceEntry dir_entry = CreateDirectoryEntry("dir101", local_id);
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(dir_entry, &local_id));
EXPECT_EQ("drive/root/dir1/dir101",
resource_metadata_->GetFilePath(local_id).AsUTF8Unsafe());
ResourceEntry file_entry3 = CreateFileEntry("file103", "id:invalid");
EXPECT_EQ(FILE_ERROR_NOT_FOUND,
resource_metadata_->AddEntry(file_entry3, &local_id));
EXPECT_EQ(FILE_ERROR_EXISTS,
resource_metadata_->AddEntry(file_entry, &local_id));
}
TEST_F(ResourceMetadataTest, RemoveEntry) {
std::string file9_local_id;
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetIdByPath(
base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3/file9"),
&file9_local_id));
ResourceEntry entry;
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryById(
file9_local_id, &entry));
EXPECT_EQ("file9", entry.base_name());
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->RemoveEntry(file9_local_id));
EXPECT_EQ(FILE_ERROR_NOT_FOUND, resource_metadata_->GetResourceEntryById(
file9_local_id, &entry));
std::string dir3_local_id;
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetIdByPath(
base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3"), &dir3_local_id));
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryById(
dir3_local_id, &entry));
EXPECT_EQ("dir3", entry.base_name());
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->RemoveEntry(dir3_local_id));
EXPECT_EQ(FILE_ERROR_NOT_FOUND, resource_metadata_->GetResourceEntryById(
dir3_local_id, &entry));
EXPECT_EQ(FILE_ERROR_NOT_FOUND, resource_metadata_->RemoveEntry("foo"));
EXPECT_EQ(FILE_ERROR_ACCESS_DENIED, resource_metadata_->RemoveEntry(
util::kDriveGrandRootLocalId));
}
TEST_F(ResourceMetadataTest, GetResourceEntryById_RootDirectory) {
ResourceEntry entry;
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryById(
util::kDriveGrandRootLocalId, &entry));
EXPECT_EQ("drive", entry.base_name());
}
TEST_F(ResourceMetadataTest, GetResourceEntryById) {
std::string local_id;
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetIdByPath(
base::FilePath::FromUTF8Unsafe("drive/root/dir1/file4"), &local_id));
ResourceEntry entry;
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryById(
local_id, &entry));
EXPECT_EQ("file4", entry.base_name());
EXPECT_EQ(FILE_ERROR_NOT_FOUND, resource_metadata_->GetResourceEntryById(
"file:non_existing", &entry));
}
TEST_F(ResourceMetadataTest, Iterate) {
scoped_ptr<ResourceMetadata::Iterator> it = resource_metadata_->GetIterator();
ASSERT_TRUE(it);
int file_count = 0, directory_count = 0;
for (; !it->IsAtEnd(); it->Advance()) {
if (!it->GetValue().file_info().is_directory())
++file_count;
else
++directory_count;
}
EXPECT_EQ(7, file_count);
EXPECT_EQ(7, directory_count);
}
TEST_F(ResourceMetadataTest, DuplicatedNames) {
std::string root_local_id;
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->GetIdByPath(
base::FilePath::FromUTF8Unsafe("drive/root"), &root_local_id));
ResourceEntry entry;
std::string dir_id_0;
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(
CreateDirectoryEntryWithResourceId(
"foo", "foo0", root_local_id), &dir_id_0));
std::string dir_id_1;
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(
CreateDirectoryEntryWithResourceId(
"foo", "foo1", root_local_id), &dir_id_1));
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryById(
dir_id_0, &entry));
EXPECT_EQ("foo", entry.base_name());
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryById(
dir_id_1, &entry));
EXPECT_EQ("foo (1)", entry.base_name());
std::string file_id_0;
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(
CreateFileEntryWithResourceId(
"bar.txt", "bar0", dir_id_0), &file_id_0));
std::string file_id_1;
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(
CreateFileEntryWithResourceId(
"bar.txt", "bar1", dir_id_0), &file_id_1));
std::string file_id_2;
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(
CreateFileEntryWithResourceId(
"bar.txt", "bar2", dir_id_0), &file_id_2));
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryById(
file_id_0, &entry));
EXPECT_EQ("bar.txt", entry.base_name());
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryById(
file_id_1, &entry));
EXPECT_EQ("bar (1).txt", entry.base_name());
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryById(
file_id_2, &entry));
EXPECT_EQ("bar (2).txt", entry.base_name());
std::string file_id_3;
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(
CreateFileEntryWithResourceId(
"bar.txt", "bar3", dir_id_1), &file_id_3));
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryById(
file_id_3, &entry));
EXPECT_EQ("bar.txt", entry.base_name());
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryByPath(
base::FilePath::FromUTF8Unsafe("drive/root/foo/bar (2).txt"), &entry));
EXPECT_EQ("bar2", entry.resource_id());
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryByPath(
base::FilePath::FromUTF8Unsafe("drive/root/foo (1)/bar.txt"), &entry));
EXPECT_EQ("bar3", entry.resource_id());
}
TEST_F(ResourceMetadataTest, EncodedNames) {
std::string root_local_id;
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->GetIdByPath(
base::FilePath::FromUTF8Unsafe("drive/root"), &root_local_id));
ResourceEntry entry;
std::string dir_id;
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(
CreateDirectoryEntry("\\(^o^)/", root_local_id), &dir_id));
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryById(
dir_id, &entry));
EXPECT_EQ("\\(^o^)_", entry.base_name());
std::string file_id;
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(
CreateFileEntryWithResourceId("Slash /.txt", "myfile", dir_id),
&file_id));
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryById(
file_id, &entry));
EXPECT_EQ("Slash _.txt", entry.base_name());
ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->GetResourceEntryByPath(
base::FilePath::FromUTF8Unsafe(
"drive/root/\\(^o^)_/Slash _.txt"),
&entry));
EXPECT_EQ("myfile", entry.resource_id());
}
TEST_F(ResourceMetadataTest, Reset) {
std::vector<ResourceEntry> entries;
ASSERT_EQ(FILE_ERROR_OK,
resource_metadata_->ReadDirectoryByPath(
base::FilePath::FromUTF8Unsafe("drive/root"), &entries));
ASSERT_FALSE(entries.empty());
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->Reset());
EXPECT_EQ(0, resource_metadata_->GetLargestChangestamp());
ResourceEntry entry;
ASSERT_EQ(FILE_ERROR_OK,
resource_metadata_->GetResourceEntryByPath(
base::FilePath::FromUTF8Unsafe("drive"), &entry));
EXPECT_EQ("drive", entry.base_name());
ASSERT_TRUE(entry.file_info().is_directory());
EXPECT_EQ(util::kDriveGrandRootLocalId, entry.local_id());
ASSERT_EQ(FILE_ERROR_OK,
resource_metadata_->ReadDirectoryByPath(
base::FilePath::FromUTF8Unsafe("drive"), &entries));
EXPECT_EQ(3U, entries.size());
ASSERT_EQ(FILE_ERROR_OK,
resource_metadata_->ReadDirectoryByPath(
base::FilePath::FromUTF8Unsafe("drive/other"), &entries));
EXPECT_TRUE(entries.empty());
ASSERT_EQ(FILE_ERROR_OK,
resource_metadata_->ReadDirectoryByPath(
base::FilePath::FromUTF8Unsafe("drive/trash"), &entries));
EXPECT_TRUE(entries.empty());
}
}
}