Index: chrome/browser/chromeos/drive/resource_metadata_unittest.cc |
diff --git a/chrome/browser/chromeos/drive/resource_metadata_unittest.cc b/chrome/browser/chromeos/drive/resource_metadata_unittest.cc |
index 5900546aa6203eb299a64e79dec16aa88b32c0b6..a157a08b9d46f8f621ddef88915ed44c6da27922 100644 |
--- a/chrome/browser/chromeos/drive/resource_metadata_unittest.cc |
+++ b/chrome/browser/chromeos/drive/resource_metadata_unittest.cc |
@@ -537,231 +537,6 @@ TEST_F(ResourceMetadataTestOnUIThread, RenameEntry) { |
EXPECT_EQ(base::FilePath(), drive_file_path); |
} |
-TEST_F(ResourceMetadataTestOnUIThread, RefreshDirectory_EmptyMap) { |
- base::FilePath kDirectoryPath(FILE_PATH_LITERAL("drive/root/dir1")); |
- const int64 kNewChangestamp = kTestChangestamp + 1; |
- |
- // Read the directory. |
- FileError error = FILE_ERROR_FAILED; |
- scoped_ptr<ResourceEntryVector> entries; |
- entries = ReadDirectoryByPathSync(base::FilePath(kDirectoryPath)); |
- ASSERT_TRUE(entries.get()); |
- // "file4", "file5", "dir3" should exist in drive/dir1. |
- 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]); |
- |
- // Get the directory. |
- scoped_ptr<ResourceEntry> dir1_proto; |
- dir1_proto = GetResourceEntryByPathSync(kDirectoryPath); |
- ASSERT_TRUE(dir1_proto.get()); |
- // The changestamp should be initially kTestChangestamp. |
- EXPECT_EQ(kTestChangestamp, |
- dir1_proto->directory_specific_info().changestamp()); |
- |
- // Update the directory with an empty map. |
- base::FilePath file_path; |
- ResourceEntryMap entry_map; |
- resource_metadata_->RefreshDirectoryOnUIThread( |
- DirectoryFetchInfo(dir1_proto->resource_id(), kNewChangestamp), |
- entry_map, |
- google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); |
- test_util::RunBlockingPoolTask(); |
- EXPECT_EQ(FILE_ERROR_OK, error); |
- EXPECT_EQ(kDirectoryPath, file_path); |
- |
- // Get the directory again. |
- dir1_proto = GetResourceEntryByPathSync(kDirectoryPath); |
- ASSERT_TRUE(dir1_proto.get()); |
- // The new changestamp should be set. |
- EXPECT_EQ(kNewChangestamp, |
- dir1_proto->directory_specific_info().changestamp()); |
- |
- // Read the directory again. |
- entries = ReadDirectoryByPathSync(base::FilePath(kDirectoryPath)); |
- ASSERT_TRUE(entries.get()); |
-} |
- |
-TEST_F(ResourceMetadataTestOnUIThread, RefreshDirectory_NonEmptyMap) { |
- base::FilePath kDirectoryPath(FILE_PATH_LITERAL("drive/root/dir1")); |
- const int64 kNewChangestamp = kTestChangestamp + 1; |
- |
- // Read the directory. |
- FileError error = FILE_ERROR_FAILED; |
- scoped_ptr<ResourceEntryVector> entries; |
- entries = ReadDirectoryByPathSync(kDirectoryPath); |
- ASSERT_TRUE(entries.get()); |
- // "file4", "file5", "dir3" should exist in drive/dir1. |
- 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]); |
- |
- // Get the directory dir1. |
- scoped_ptr<ResourceEntry> dir1_proto; |
- dir1_proto = GetResourceEntryByPathSync(kDirectoryPath); |
- ASSERT_TRUE(dir1_proto.get()); |
- // The changestamp should be initially kTestChangestamp. |
- EXPECT_EQ(kTestChangestamp, |
- dir1_proto->directory_specific_info().changestamp()); |
- |
- // Get the directory dir2 (existing non-child directory). |
- // This directory will be moved to "drive/dir1/dir2". |
- scoped_ptr<ResourceEntry> dir2_proto; |
- dir2_proto = GetResourceEntryByPathSync( |
- base::FilePath::FromUTF8Unsafe("drive/root/dir2")); |
- ASSERT_TRUE(dir2_proto.get()); |
- EXPECT_EQ(kTestChangestamp, |
- dir2_proto->directory_specific_info().changestamp()); |
- // Change the parent resource ID, as dir2 will be moved to "drive/dir1/dir2". |
- dir2_proto->set_parent_local_id(dir1_proto->resource_id()); |
- |
- // Get the directory dir3 (existing child directory). |
- // This directory will remain as "drive/dir1/dir3". |
- scoped_ptr<ResourceEntry> dir3_proto; |
- dir3_proto = GetResourceEntryByPathSync( |
- base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3")); |
- ASSERT_TRUE(dir3_proto.get()); |
- EXPECT_EQ(kTestChangestamp, |
- dir3_proto->directory_specific_info().changestamp()); |
- |
- // Create a map. |
- 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(dir1_proto->resource_id()); |
- entry_map["new_file_id"] = new_file; |
- |
- // Add a new directory to the map. |
- ResourceEntry new_directory; |
- new_directory.set_title("new_directory"); |
- new_directory.set_resource_id("new_directory_id"); |
- new_directory.set_parent_local_id(dir1_proto->resource_id()); |
- new_directory.mutable_file_info()->set_is_directory(true); |
- entry_map["new_directory_id"] = new_directory; |
- |
- // Add dir2 and dir3 as well. |
- entry_map[dir2_proto->resource_id()] = *dir2_proto; |
- entry_map[dir3_proto->resource_id()] = *dir3_proto; |
- |
- // Update the directory with the map. |
- base::FilePath file_path; |
- resource_metadata_->RefreshDirectoryOnUIThread( |
- DirectoryFetchInfo(dir1_proto->resource_id(), kNewChangestamp), |
- entry_map, |
- google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); |
- test_util::RunBlockingPoolTask(); |
- EXPECT_EQ(FILE_ERROR_OK, error); |
- EXPECT_EQ(kDirectoryPath, file_path); |
- |
- // Get the directory again. |
- dir1_proto = GetResourceEntryByPathSync(kDirectoryPath); |
- ASSERT_TRUE(dir1_proto.get()); |
- // The new changestamp should be set. |
- EXPECT_EQ(kNewChangestamp, |
- dir1_proto->directory_specific_info().changestamp()); |
- |
- // Read the directory again. |
- entries = ReadDirectoryByPathSync(kDirectoryPath); |
- ASSERT_TRUE(entries.get()); |
- // "new_file", "new_directory", "dir2" should now be added. |
- base_names = GetSortedBaseNames(*entries); |
- EXPECT_EQ(1, std::count(base_names.begin(), base_names.end(), "dir2")); |
- EXPECT_EQ(1, |
- std::count(base_names.begin(), base_names.end(), "new_directory")); |
- EXPECT_EQ(1, |
- std::count(base_names.begin(), base_names.end(), "new_file")); |
- |
- // Get the new directory. |
- scoped_ptr<ResourceEntry> new_directory_proto; |
- new_directory_proto = GetResourceEntryByPathSync( |
- base::FilePath::FromUTF8Unsafe("drive/root/dir1/new_directory")); |
- ASSERT_TRUE(new_directory_proto.get()); |
- // The changestamp should be 0 for a new directory. |
- EXPECT_EQ(0, new_directory_proto->directory_specific_info().changestamp()); |
- |
- // Get the directory dir3 (existing child directory) again. |
- dir3_proto = GetResourceEntryByPathSync( |
- base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3")); |
- ASSERT_TRUE(dir3_proto.get()); |
- // The changestamp should not be changed. |
- EXPECT_EQ(kTestChangestamp, |
- dir3_proto->directory_specific_info().changestamp()); |
- |
- // Read the directory dir3. The contents should remain. |
- // See the comment at Init() for the contents of the dir3. |
- entries = ReadDirectoryByPathSync( |
- base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir3")); |
- ASSERT_TRUE(entries.get()); |
- ASSERT_EQ(2U, entries->size()); |
- |
- // Get the directory dir2 (existing non-child directory) again using the |
- // old path. This should fail, as dir2 is now moved to drive/dir1/dir2. |
- dir2_proto = GetResourceEntryByPathSync( |
- base::FilePath::FromUTF8Unsafe("drive/root/dir2")); |
- ASSERT_FALSE(dir2_proto.get()); |
- |
- // Get the directory dir2 (existing non-child directory) again using the |
- // new path. This should succeed. |
- dir2_proto = GetResourceEntryByPathSync( |
- base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir2")); |
- ASSERT_TRUE(dir2_proto.get()); |
- // The changestamp should not be changed. |
- EXPECT_EQ(kTestChangestamp, |
- dir2_proto->directory_specific_info().changestamp()); |
- |
- // Read the directory dir2. The contents should remain. |
- // See the comment at Init() for the contents of the dir2. |
- entries = ReadDirectoryByPathSync( |
- base::FilePath::FromUTF8Unsafe("drive/root/dir1/dir2")); |
- ASSERT_TRUE(entries.get()); |
- ASSERT_EQ(3U, entries->size()); |
-} |
- |
-TEST_F(ResourceMetadataTestOnUIThread, RefreshDirectory_WrongParentResourceId) { |
- base::FilePath kDirectoryPath(FILE_PATH_LITERAL("drive/root/dir1")); |
- const int64 kNewChangestamp = kTestChangestamp + 1; |
- |
- // Get the directory dir1. |
- scoped_ptr<ResourceEntry> dir1_proto; |
- dir1_proto = GetResourceEntryByPathSync(kDirectoryPath); |
- ASSERT_TRUE(dir1_proto.get()); |
- |
- // Create a map and add a new file to it. |
- ResourceEntryMap entry_map; |
- ResourceEntry new_file; |
- new_file.set_title("new_file"); |
- new_file.set_resource_id("new_file_id"); |
- // Set a random parent resource ID. This entry should not be added because |
- // the parent resource ID does not match dir1_proto->resource_id(). |
- new_file.set_parent_local_id("some-random-resource-id"); |
- entry_map["new_file_id"] = new_file; |
- |
- // Update the directory with the map. |
- base::FilePath file_path; |
- FileError error = FILE_ERROR_FAILED; |
- resource_metadata_->RefreshDirectoryOnUIThread( |
- DirectoryFetchInfo(dir1_proto->resource_id(), kNewChangestamp), |
- entry_map, |
- google_apis::test_util::CreateCopyResultCallback(&error, &file_path)); |
- test_util::RunBlockingPoolTask(); |
- EXPECT_EQ(FILE_ERROR_OK, error); |
- EXPECT_EQ(kDirectoryPath, file_path); |
- |
- // Read the directory. Confirm that the new file is not added. |
- scoped_ptr<ResourceEntryVector> entries; |
- entries = ReadDirectoryByPathSync(kDirectoryPath); |
- ASSERT_TRUE(entries.get()); |
- std::vector<std::string> base_names = GetSortedBaseNames(*entries); |
- EXPECT_EQ(0, std::count(base_names.begin(), base_names.end(), "new_file")); |
-} |
- |
TEST_F(ResourceMetadataTestOnUIThread, AddEntry) { |
FileError error = FILE_ERROR_FAILED; |
base::FilePath drive_file_path; |