Index: chrome/browser/chromeos/drive/change_list_processor_unittest.cc |
diff --git a/chrome/browser/chromeos/drive/change_list_processor_unittest.cc b/chrome/browser/chromeos/drive/change_list_processor_unittest.cc |
index 4f8a914eaab9e5a1a0dfb3f5ba7d1651338c388e..221ff98e587742bddb2d66bc3a54565274d5fbcc 100644 |
--- a/chrome/browser/chromeos/drive/change_list_processor_unittest.cc |
+++ b/chrome/browser/chromeos/drive/change_list_processor_unittest.cc |
@@ -24,6 +24,7 @@ namespace { |
const int64 kBaseResourceListChangestamp = 123; |
const char kBaseResourceListFile[] = "gdata/root_feed.json"; |
+const char kRootId[] = "fake_root"; |
enum FileOrDirectory { |
FILE, |
@@ -68,7 +69,7 @@ class ChangeListProcessorTest : public testing::Test { |
scoped_ptr<google_apis::AboutResource> about_resource( |
new google_apis::AboutResource); |
about_resource->set_largest_change_id(kBaseResourceListChangestamp); |
- about_resource->set_root_folder_id("fake_root"); |
+ about_resource->set_root_folder_id(kRootId); |
ChangeListProcessor processor(metadata_.get()); |
processor.Apply(about_resource.Pass(), |
@@ -112,25 +113,25 @@ TEST_F(ChangeListProcessorTest, ApplyFullResourceList) { |
const EntryExpectation kExpected[] = { |
// Root files |
{"drive/root", |
- "fake_root", util::kDriveGrandRootSpecialResourceId, DIRECTORY}, |
+ kRootId, util::kDriveGrandRootSpecialResourceId, DIRECTORY}, |
{"drive/root/File 1.txt", |
- "file:2_file_resource_id", "fake_root", FILE}, |
+ "file:2_file_resource_id", kRootId, FILE}, |
{"drive/root/Slash \xE2\x88\x95 in file 1.txt", |
- "file:slash_file_resource_id", "fake_root", FILE}, |
+ "file:slash_file_resource_id", kRootId, FILE}, |
{"drive/root/Document 1 excludeDir-test.gdoc", |
- "document:5_document_resource_id", "fake_root", FILE}, |
+ "document:5_document_resource_id", kRootId, FILE}, |
// Subdirectory files |
{"drive/root/Directory 1", |
- "folder:1_folder_resource_id", "fake_root", DIRECTORY}, |
+ "folder:1_folder_resource_id", kRootId, DIRECTORY}, |
{"drive/root/Directory 1/SubDirectory File 1.txt", |
"file:subdirectory_file_1_id", "folder:1_folder_resource_id", FILE}, |
{"drive/root/Directory 1/Shared To The Account Owner.txt", |
"file:subdirectory_unowned_file_1_id", |
"folder:1_folder_resource_id", FILE}, |
{"drive/root/Directory 2 excludeDir-test", |
- "folder:sub_dir_folder_2_self_link", "fake_root", DIRECTORY}, |
+ "folder:sub_dir_folder_2_self_link", kRootId, DIRECTORY}, |
{"drive/root/Slash \xE2\x88\x95 in directory", |
- "folder:slash_dir_folder_resource_id", "fake_root", DIRECTORY}, |
+ "folder:slash_dir_folder_resource_id", kRootId, DIRECTORY}, |
{"drive/root/Slash \xE2\x88\x95 in directory/Slash SubDir File.txt", |
"file:slash_subdir_file", |
"folder:slash_dir_folder_resource_id", FILE}, |
@@ -167,7 +168,6 @@ TEST_F(ChangeListProcessorTest, DeltaFileAddedInNewDirectory) { |
ChangeListProcessor::ConvertToMap( |
ParseChangeList(kTestJson), &entry_map, NULL); |
- const std::string kRootId("fake_root"); |
const std::string kNewFolderId("folder:new_folder_resource_id"); |
const std::string kNewFileId("document:file_added_in_new_dir_id"); |
@@ -249,7 +249,6 @@ TEST_F(ChangeListProcessorTest, DeltaFileMovedFromDirectoryToRoot) { |
ChangeListProcessor::ConvertToMap( |
ParseChangeList(kTestJson), &entry_map, NULL); |
- const std::string kRootId("fake_root"); |
const std::string kMovedId("file:subdirectory_file_1_id"); |
const std::string kSrcId("folder:1_folder_resource_id"); |
@@ -285,7 +284,6 @@ TEST_F(ChangeListProcessorTest, DeltaFileRenamedInDirectory) { |
ChangeListProcessor::ConvertToMap( |
ParseChangeList(kTestJson), &entry_map, NULL); |
- const std::string kRootId("fake_root"); |
const std::string kRenamedId("file:subdirectory_file_1_id"); |
const std::string kParentId("folder:1_folder_resource_id"); |
@@ -321,7 +319,7 @@ TEST_F(ChangeListProcessorTest, DeltaAddAndDeleteFileInRoot) { |
const char kTestJsonDelete[] = |
"gdata/delta_file_deleted_in_root.json"; |
- const std::string kParentId("fake_root"); |
+ const std::string kParentId(kRootId); |
const std::string kFileId("document:added_in_root_id"); |
ChangeListProcessor::ResourceEntryMap entry_map; |
@@ -431,7 +429,6 @@ TEST_F(ChangeListProcessorTest, DeltaAddFileToNewButDeletedDirectory) { |
ChangeListProcessor::ConvertToMap( |
ParseChangeList(kTestJson), &entry_map, NULL); |
- const std::string kRootId("fake_root"); |
const std::string kDirId("folder:new_folder_resource_id"); |
const std::string kFileId("pdf:file_added_in_deleted_dir_id"); |
@@ -454,5 +451,80 @@ TEST_F(ChangeListProcessorTest, DeltaAddFileToNewButDeletedDirectory) { |
EXPECT_TRUE(changed_dirs.empty()); |
} |
+TEST_F(ChangeListProcessorTest, RefreshDirectory) { |
+ // Prepare metadata. |
+ ApplyFullResourceList(ParseChangeList(kBaseResourceListFile)); |
+ |
+ // Create a map. |
+ ChangeListProcessor::ResourceEntryMap entry_map; |
+ |
+ // Add a new file to the map. |
+ ResourceEntry new_file; |
+ new_file.set_title("new_file"); |
+ new_file.set_resource_id("new_file_id"); |
+ new_file.set_parent_local_id(kRootId); |
+ entry_map["new_file_id"] = new_file; |
+ |
+ // Add "Directory 1" to the map with a new name. |
+ ResourceEntry dir1; |
+ EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryByPath( |
+ util::GetDriveMyDriveRootPath().AppendASCII("Directory 1"), &dir1)); |
+ dir1.set_title(dir1.title() + " (renamed)"); |
+ entry_map[dir1.resource_id()] = dir1; |
+ |
+ // Update the directory with the map. |
+ const int64 kNewChangestamp = 12345; |
+ base::FilePath file_path; |
+ EXPECT_EQ(FILE_ERROR_OK, ChangeListProcessor::RefreshDirectory( |
+ metadata_.get(), |
+ DirectoryFetchInfo(kRootId, kNewChangestamp), |
+ entry_map, |
+ &file_path)); |
+ EXPECT_EQ(util::GetDriveMyDriveRootPath().value(), file_path.value()); |
+ |
+ // The new changestamp should be set. |
+ ResourceEntry entry; |
+ EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryByPath( |
+ util::GetDriveMyDriveRootPath(), &entry)); |
+ EXPECT_EQ(kNewChangestamp, entry.directory_specific_info().changestamp()); |
+ |
+ // "new_file" should be added. |
+ EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryByPath( |
+ util::GetDriveMyDriveRootPath().AppendASCII(new_file.title()), &entry)); |
+ |
+ // "Directory 1" should be renamed. |
+ EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryByPath( |
+ util::GetDriveMyDriveRootPath().AppendASCII(dir1.title()), &entry)); |
+} |
+ |
+TEST_F(ChangeListProcessorTest, RefreshDirectory_WrongParentId) { |
+ // Prepare metadata. |
+ ApplyFullResourceList(ParseChangeList(kBaseResourceListFile)); |
+ |
+ // Create a map and add a new file to it. |
+ ChangeListProcessor::ResourceEntryMap entry_map; |
+ ResourceEntry new_file; |
+ new_file.set_title("new_file"); |
+ new_file.set_resource_id("new_file_id"); |
+ // This entry should not be added because the parent ID does not match. |
+ new_file.set_parent_local_id("some-random-resource-id"); |
+ entry_map["new_file_id"] = new_file; |
+ |
+ // Update the directory with the map. |
+ const int64 kNewChangestamp = 12345; |
+ base::FilePath file_path; |
+ EXPECT_EQ(FILE_ERROR_OK, ChangeListProcessor::RefreshDirectory( |
+ metadata_.get(), |
+ DirectoryFetchInfo(kRootId, kNewChangestamp), |
+ entry_map, |
+ &file_path)); |
+ EXPECT_EQ(util::GetDriveMyDriveRootPath().value(), file_path.value()); |
+ |
+ // "new_file" should not be added. |
+ ResourceEntry entry; |
+ EXPECT_EQ(FILE_ERROR_NOT_FOUND, metadata_->GetResourceEntryByPath( |
+ util::GetDriveMyDriveRootPath().AppendASCII(new_file.title()), &entry)); |
+} |
+ |
} // namespace internal |
} // namespace drive |