| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/drive/change_list_processor.h" | 5 #include "chrome/browser/chromeos/drive/change_list_processor.h" |
| 6 | 6 |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/chromeos/drive/drive.pb.h" | 10 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 11 #include "chrome/browser/chromeos/drive/file_system_util.h" | 11 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 12 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 12 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
| 13 #include "chrome/browser/chromeos/drive/test_util.h" | 13 #include "chrome/browser/chromeos/drive/test_util.h" |
| 14 #include "content/public/test/test_browser_thread_bundle.h" | 14 #include "content/public/test/test_browser_thread_bundle.h" |
| 15 #include "google_apis/drive/drive_api_parser.h" | 15 #include "google_apis/drive/drive_api_parser.h" |
| 16 #include "google_apis/drive/gdata_wapi_parser.h" | 16 #include "google_apis/drive/gdata_wapi_parser.h" |
| 17 #include "google_apis/drive/test_util.h" | 17 #include "google_apis/drive/test_util.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 namespace drive { | 20 namespace drive { |
| 21 namespace internal { | 21 namespace internal { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 const int64 kBaseResourceListChangestamp = 123; | 25 const int64 kBaseResourceListChangestamp = 123; |
| 26 const char kBaseResourceListFile[] = "gdata/root_feed.json"; | |
| 27 const char kRootId[] = "fake_root"; | 26 const char kRootId[] = "fake_root"; |
| 28 | 27 |
| 29 enum FileOrDirectory { | 28 enum FileOrDirectory { |
| 30 FILE, | 29 FILE, |
| 31 DIRECTORY, | 30 DIRECTORY, |
| 32 }; | 31 }; |
| 33 | 32 |
| 34 struct EntryExpectation { | 33 struct EntryExpectation { |
| 35 std::string path; | 34 std::string path; |
| 36 std::string id; | 35 std::string id; |
| 37 std::string parent_id; | 36 std::string parent_id; |
| 38 FileOrDirectory type; | 37 FileOrDirectory type; |
| 39 }; | 38 }; |
| 40 | 39 |
| 41 typedef std::map<std::string, ResourceEntry> ResourceEntryMap; | 40 // Returns a basic change list which contains some files and directories. |
| 42 typedef std::map<std::string, std::string> ParentResourceIdMap; | 41 ScopedVector<ChangeList> CreateBaseChangeList() { |
| 43 void ConvertToMap(ScopedVector<ChangeList> change_lists, | 42 ScopedVector<ChangeList> change_lists; |
| 44 ResourceEntryMap* entry_map, | 43 change_lists.push_back(new ChangeList); |
| 45 ParentResourceIdMap* parent_resource_id_map) { | |
| 46 for (size_t i = 0; i < change_lists.size(); ++i) { | |
| 47 const std::vector<ResourceEntry>& entries = change_lists[i]->entries(); | |
| 48 const std::vector<std::string>& parent_resource_ids = | |
| 49 change_lists[i]->parent_resource_ids(); | |
| 50 EXPECT_EQ(entries.size(), parent_resource_ids.size()); | |
| 51 | 44 |
| 52 for (size_t i = 0; i < entries.size(); ++i) { | 45 // Add directories to the change list. |
| 53 const std::string& resource_id = entries[i].resource_id(); | 46 ResourceEntry directory; |
| 54 (*parent_resource_id_map)[resource_id] = parent_resource_ids[i]; | 47 directory.mutable_file_info()->set_is_directory(true); |
| 55 (*entry_map)[resource_id] = entries[i]; | 48 |
| 56 } | 49 directory.set_title("Directory 1"); |
| 57 } | 50 directory.set_resource_id("folder:1_folder_resource_id"); |
| 51 change_lists[0]->mutable_entries()->push_back(directory); |
| 52 change_lists[0]->mutable_parent_resource_ids()->push_back(kRootId); |
| 53 |
| 54 directory.set_title("Sub Directory Folder"); |
| 55 directory.set_resource_id("folder:sub_dir_folder_resource_id"); |
| 56 change_lists[0]->mutable_entries()->push_back(directory); |
| 57 change_lists[0]->mutable_parent_resource_ids()->push_back( |
| 58 "folder:1_folder_resource_id"); |
| 59 |
| 60 directory.set_title("Sub Sub Directory Folder"); |
| 61 directory.set_resource_id("folder:sub_sub_directory_folder_id"); |
| 62 change_lists[0]->mutable_entries()->push_back(directory); |
| 63 change_lists[0]->mutable_parent_resource_ids()->push_back( |
| 64 "folder:sub_dir_folder_resource_id"); |
| 65 |
| 66 directory.set_title("Directory 2 excludeDir-test"); |
| 67 directory.set_resource_id("folder:sub_dir_folder_2_self_link"); |
| 68 change_lists[0]->mutable_entries()->push_back(directory); |
| 69 change_lists[0]->mutable_parent_resource_ids()->push_back(kRootId); |
| 70 |
| 71 // Add files to the change list. |
| 72 ResourceEntry file; |
| 73 |
| 74 file.set_title("File 1.txt"); |
| 75 file.set_resource_id("file:2_file_resource_id"); |
| 76 change_lists[0]->mutable_entries()->push_back(file); |
| 77 change_lists[0]->mutable_parent_resource_ids()->push_back(kRootId); |
| 78 |
| 79 file.set_title("SubDirectory File 1.txt"); |
| 80 file.set_resource_id("file:subdirectory_file_1_id"); |
| 81 change_lists[0]->mutable_entries()->push_back(file); |
| 82 change_lists[0]->mutable_parent_resource_ids()->push_back( |
| 83 "folder:1_folder_resource_id"); |
| 84 |
| 85 file.set_title("Orphan File 1.txt"); |
| 86 file.set_resource_id("file:1_orphanfile_resource_id"); |
| 87 change_lists[0]->mutable_entries()->push_back(file); |
| 88 change_lists[0]->mutable_parent_resource_ids()->push_back(""); |
| 89 |
| 90 change_lists[0]->set_largest_changestamp(kBaseResourceListChangestamp); |
| 91 return change_lists.Pass(); |
| 58 } | 92 } |
| 59 | 93 |
| 60 class ChangeListProcessorTest : public testing::Test { | 94 class ChangeListProcessorTest : public testing::Test { |
| 61 protected: | 95 protected: |
| 62 virtual void SetUp() OVERRIDE { | 96 virtual void SetUp() OVERRIDE { |
| 63 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 97 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 64 | 98 |
| 65 metadata_storage_.reset(new ResourceMetadataStorage( | 99 metadata_storage_.reset(new ResourceMetadataStorage( |
| 66 temp_dir_.path(), base::MessageLoopProxy::current().get())); | 100 temp_dir_.path(), base::MessageLoopProxy::current().get())); |
| 67 ASSERT_TRUE(metadata_storage_->Initialize()); | 101 ASSERT_TRUE(metadata_storage_->Initialize()); |
| 68 | 102 |
| 69 metadata_.reset(new internal::ResourceMetadata( | 103 metadata_.reset(new internal::ResourceMetadata( |
| 70 metadata_storage_.get(), base::MessageLoopProxy::current())); | 104 metadata_storage_.get(), base::MessageLoopProxy::current())); |
| 71 ASSERT_EQ(FILE_ERROR_OK, metadata_->Initialize()); | 105 ASSERT_EQ(FILE_ERROR_OK, metadata_->Initialize()); |
| 72 } | 106 } |
| 73 | 107 |
| 74 // Parses a json file at |test_data_path| relative to Chrome test directory | |
| 75 // into a ScopedVector<drive::internal::ChangeList>. | |
| 76 ScopedVector<ChangeList> ParseChangeList(const std::string& test_data_path) { | |
| 77 ScopedVector<ChangeList> changes; | |
| 78 changes.push_back(new ChangeList( | |
| 79 *google_apis::ResourceList::ExtractAndParse( | |
| 80 *google_apis::test_util::LoadJSONFile( | |
| 81 test_data_path)))); | |
| 82 return changes.Pass(); | |
| 83 } | |
| 84 | |
| 85 // Applies the |changes| to |metadata_| as a full resource list of changestamp | 108 // Applies the |changes| to |metadata_| as a full resource list of changestamp |
| 86 // |kBaseResourceListChangestamp|. | 109 // |kBaseResourceListChangestamp|. |
| 87 FileError ApplyFullResourceList(ScopedVector<ChangeList> changes) { | 110 FileError ApplyFullResourceList(ScopedVector<ChangeList> changes) { |
| 88 scoped_ptr<google_apis::AboutResource> about_resource( | 111 scoped_ptr<google_apis::AboutResource> about_resource( |
| 89 new google_apis::AboutResource); | 112 new google_apis::AboutResource); |
| 90 about_resource->set_largest_change_id(kBaseResourceListChangestamp); | 113 about_resource->set_largest_change_id(kBaseResourceListChangestamp); |
| 91 about_resource->set_root_folder_id(kRootId); | 114 about_resource->set_root_folder_id(kRootId); |
| 92 | 115 |
| 93 ChangeListProcessor processor(metadata_.get()); | 116 ChangeListProcessor processor(metadata_.get()); |
| 94 return processor.Apply(about_resource.Pass(), | 117 return processor.Apply(about_resource.Pass(), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 content::TestBrowserThreadBundle thread_bundle_; | 150 content::TestBrowserThreadBundle thread_bundle_; |
| 128 base::ScopedTempDir temp_dir_; | 151 base::ScopedTempDir temp_dir_; |
| 129 scoped_ptr<ResourceMetadataStorage, | 152 scoped_ptr<ResourceMetadataStorage, |
| 130 test_util::DestroyHelperForTests> metadata_storage_; | 153 test_util::DestroyHelperForTests> metadata_storage_; |
| 131 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> metadata_; | 154 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> metadata_; |
| 132 }; | 155 }; |
| 133 | 156 |
| 134 } // namespace | 157 } // namespace |
| 135 | 158 |
| 136 TEST_F(ChangeListProcessorTest, ApplyFullResourceList) { | 159 TEST_F(ChangeListProcessorTest, ApplyFullResourceList) { |
| 137 EXPECT_EQ(FILE_ERROR_OK, | 160 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); |
| 138 ApplyFullResourceList(ParseChangeList(kBaseResourceListFile))); | |
| 139 | 161 |
| 140 const EntryExpectation kExpected[] = { | 162 const EntryExpectation kExpected[] = { |
| 141 // Root files | 163 // Root files |
| 142 {"drive/root", kRootId, "", DIRECTORY}, | 164 {"drive/root", kRootId, "", DIRECTORY}, |
| 143 {"drive/root/File 1.txt", | 165 {"drive/root/File 1.txt", |
| 144 "file:2_file_resource_id", kRootId, FILE}, | 166 "file:2_file_resource_id", kRootId, FILE}, |
| 145 {"drive/root/Slash _ in file 1.txt", | |
| 146 "file:slash_file_resource_id", kRootId, FILE}, | |
| 147 {"drive/root/Document 1 excludeDir-test.gdoc", | |
| 148 "document:5_document_resource_id", kRootId, FILE}, | |
| 149 // Subdirectory files | 167 // Subdirectory files |
| 150 {"drive/root/Directory 1", | 168 {"drive/root/Directory 1", |
| 151 "folder:1_folder_resource_id", kRootId, DIRECTORY}, | 169 "folder:1_folder_resource_id", kRootId, DIRECTORY}, |
| 152 {"drive/root/Directory 1/SubDirectory File 1.txt", | 170 {"drive/root/Directory 1/SubDirectory File 1.txt", |
| 153 "file:subdirectory_file_1_id", "folder:1_folder_resource_id", FILE}, | 171 "file:subdirectory_file_1_id", "folder:1_folder_resource_id", FILE}, |
| 154 {"drive/root/Directory 1/Shared To The Account Owner.txt", | |
| 155 "file:subdirectory_unowned_file_1_id", | |
| 156 "folder:1_folder_resource_id", FILE}, | |
| 157 {"drive/root/Directory 2 excludeDir-test", | 172 {"drive/root/Directory 2 excludeDir-test", |
| 158 "folder:sub_dir_folder_2_self_link", kRootId, DIRECTORY}, | 173 "folder:sub_dir_folder_2_self_link", kRootId, DIRECTORY}, |
| 159 {"drive/root/Slash _ in directory", | |
| 160 "folder:slash_dir_folder_resource_id", kRootId, DIRECTORY}, | |
| 161 {"drive/root/Slash _ in directory/Slash SubDir File.txt", | |
| 162 "file:slash_subdir_file", | |
| 163 "folder:slash_dir_folder_resource_id", FILE}, | |
| 164 // Deeper | 174 // Deeper |
| 165 {"drive/root/Directory 1/Sub Directory Folder", | 175 {"drive/root/Directory 1/Sub Directory Folder", |
| 166 "folder:sub_dir_folder_resource_id", | 176 "folder:sub_dir_folder_resource_id", |
| 167 "folder:1_folder_resource_id", DIRECTORY}, | 177 "folder:1_folder_resource_id", DIRECTORY}, |
| 168 {"drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder", | 178 {"drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder", |
| 169 "folder:sub_sub_directory_folder_id", | 179 "folder:sub_sub_directory_folder_id", |
| 170 "folder:sub_dir_folder_resource_id", DIRECTORY}, | 180 "folder:sub_dir_folder_resource_id", DIRECTORY}, |
| 171 // Orphan | 181 // Orphan |
| 172 {"drive/other/Orphan File 1.txt", "file:1_orphanfile_resource_id", | 182 {"drive/other/Orphan File 1.txt", "file:1_orphanfile_resource_id", |
| 173 "", FILE}, | 183 "", FILE}, |
| 174 }; | 184 }; |
| 175 | 185 |
| 176 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kExpected); ++i) { | 186 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kExpected); ++i) { |
| 177 scoped_ptr<ResourceEntry> entry = GetResourceEntry(kExpected[i].path); | 187 scoped_ptr<ResourceEntry> entry = GetResourceEntry(kExpected[i].path); |
| 178 ASSERT_TRUE(entry) << "for path: " << kExpected[i].path; | 188 ASSERT_TRUE(entry) << "for path: " << kExpected[i].path; |
| 179 EXPECT_EQ(kExpected[i].id, entry->resource_id()); | 189 EXPECT_EQ(kExpected[i].id, entry->resource_id()); |
| 180 | 190 |
| 181 ResourceEntry parent_entry; | 191 ResourceEntry parent_entry; |
| 182 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryById( | 192 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryById( |
| 183 entry->parent_local_id(), &parent_entry)); | 193 entry->parent_local_id(), &parent_entry)); |
| 184 EXPECT_EQ(kExpected[i].parent_id, parent_entry.resource_id()); | 194 EXPECT_EQ(kExpected[i].parent_id, parent_entry.resource_id()); |
| 185 EXPECT_EQ(kExpected[i].type, | 195 EXPECT_EQ(kExpected[i].type, |
| 186 entry->file_info().is_directory() ? DIRECTORY : FILE); | 196 entry->file_info().is_directory() ? DIRECTORY : FILE); |
| 187 } | 197 } |
| 188 | 198 |
| 189 EXPECT_EQ(kBaseResourceListChangestamp, metadata_->GetLargestChangestamp()); | 199 EXPECT_EQ(kBaseResourceListChangestamp, metadata_->GetLargestChangestamp()); |
| 190 } | 200 } |
| 191 | 201 |
| 192 TEST_F(ChangeListProcessorTest, DeltaFileAddedInNewDirectory) { | 202 TEST_F(ChangeListProcessorTest, DeltaFileAddedInNewDirectory) { |
| 193 const char kTestJson[] = | 203 ScopedVector<ChangeList> change_lists; |
| 194 "gdata/delta_file_added_in_new_directory.json"; | 204 change_lists.push_back(new ChangeList); |
| 195 | 205 |
| 196 ResourceEntryMap entry_map; | 206 ResourceEntry new_folder; |
| 197 ParentResourceIdMap parent_resource_id_map; | 207 new_folder.set_resource_id("folder:new_folder_resource_id"); |
| 198 ConvertToMap(ParseChangeList(kTestJson), &entry_map, &parent_resource_id_map); | 208 new_folder.set_title("New Directory"); |
| 209 new_folder.mutable_file_info()->set_is_directory(true); |
| 210 change_lists[0]->mutable_entries()->push_back(new_folder); |
| 211 change_lists[0]->mutable_parent_resource_ids()->push_back(kRootId); |
| 199 | 212 |
| 200 const std::string kNewFolderId("folder:new_folder_resource_id"); | 213 ResourceEntry new_file; |
| 201 const std::string kNewFileId("document:file_added_in_new_dir_id"); | 214 new_file.set_resource_id("document:file_added_in_new_dir_id"); |
| 215 new_file.set_title("File in new dir.txt"); |
| 216 change_lists[0]->mutable_entries()->push_back(new_file); |
| 217 change_lists[0]->mutable_parent_resource_ids()->push_back( |
| 218 new_folder.resource_id()); |
| 202 | 219 |
| 203 // Check the content of parsed ResourceEntryMap. | 220 change_lists[0]->set_largest_changestamp(16730); |
| 204 EXPECT_EQ(2U, entry_map.size()); | |
| 205 EXPECT_TRUE(entry_map.count(kNewFolderId)); | |
| 206 EXPECT_TRUE(entry_map.count(kNewFileId)); | |
| 207 EXPECT_EQ(kRootId, parent_resource_id_map[kNewFolderId]); | |
| 208 EXPECT_EQ(kNewFolderId, parent_resource_id_map[kNewFileId]); | |
| 209 EXPECT_TRUE(entry_map[kNewFolderId].file_info().is_directory()); | |
| 210 EXPECT_FALSE(entry_map[kNewFileId].file_info().is_directory()); | |
| 211 EXPECT_EQ("New Directory", entry_map[kNewFolderId].title()); | |
| 212 EXPECT_EQ("File in new dir", entry_map[kNewFileId].title()); | |
| 213 | 221 |
| 214 // Apply the changelist and check the effect. | 222 // Apply the changelist and check the effect. |
| 215 EXPECT_EQ(FILE_ERROR_OK, | 223 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); |
| 216 ApplyFullResourceList(ParseChangeList(kBaseResourceListFile))); | |
| 217 std::set<base::FilePath> changed_dirs; | 224 std::set<base::FilePath> changed_dirs; |
| 218 EXPECT_EQ(FILE_ERROR_OK, | 225 EXPECT_EQ(FILE_ERROR_OK, ApplyChangeList(change_lists.Pass(), &changed_dirs)); |
| 219 ApplyChangeList(ParseChangeList(kTestJson), &changed_dirs)); | |
| 220 | 226 |
| 221 // The value is written in kTestJson. | |
| 222 EXPECT_EQ(16730, metadata_->GetLargestChangestamp()); | 227 EXPECT_EQ(16730, metadata_->GetLargestChangestamp()); |
| 223 EXPECT_TRUE(GetResourceEntry("drive/root/New Directory")); | 228 EXPECT_TRUE(GetResourceEntry("drive/root/New Directory")); |
| 224 EXPECT_TRUE(GetResourceEntry( | 229 EXPECT_TRUE(GetResourceEntry( |
| 225 "drive/root/New Directory/File in new dir.gdoc")); | 230 "drive/root/New Directory/File in new dir.txt")); |
| 226 | 231 |
| 227 EXPECT_EQ(2U, changed_dirs.size()); | 232 EXPECT_EQ(2U, changed_dirs.size()); |
| 228 EXPECT_TRUE(changed_dirs.count( | 233 EXPECT_TRUE(changed_dirs.count( |
| 229 base::FilePath::FromUTF8Unsafe("drive/root"))); | 234 base::FilePath::FromUTF8Unsafe("drive/root"))); |
| 230 EXPECT_TRUE(changed_dirs.count( | 235 EXPECT_TRUE(changed_dirs.count( |
| 231 base::FilePath::FromUTF8Unsafe("drive/root/New Directory"))); | 236 base::FilePath::FromUTF8Unsafe("drive/root/New Directory"))); |
| 232 } | 237 } |
| 233 | 238 |
| 234 TEST_F(ChangeListProcessorTest, DeltaDirMovedFromRootToDirectory) { | 239 TEST_F(ChangeListProcessorTest, DeltaDirMovedFromRootToDirectory) { |
| 235 const char kTestJson[] = | 240 ScopedVector<ChangeList> change_lists; |
| 236 "gdata/delta_dir_moved_from_root_to_directory.json"; | 241 change_lists.push_back(new ChangeList); |
| 237 | 242 |
| 238 ResourceEntryMap entry_map; | 243 ResourceEntry entry; |
| 239 ParentResourceIdMap parent_resource_id_map; | 244 entry.set_resource_id("folder:1_folder_resource_id"); |
| 240 ConvertToMap(ParseChangeList(kTestJson), &entry_map, &parent_resource_id_map); | 245 entry.set_title("Directory 1"); |
| 246 entry.mutable_file_info()->set_is_directory(true); |
| 247 change_lists[0]->mutable_entries()->push_back(entry); |
| 248 change_lists[0]->mutable_parent_resource_ids()->push_back( |
| 249 "folder:sub_dir_folder_2_self_link"); |
| 241 | 250 |
| 242 const std::string kMovedId("folder:1_folder_resource_id"); | 251 change_lists[0]->set_largest_changestamp(16809); |
| 243 const std::string kDestId("folder:sub_dir_folder_2_self_link"); | |
| 244 | |
| 245 // Check the content of parsed ResourceEntryMap. | |
| 246 EXPECT_EQ(2U, entry_map.size()); | |
| 247 EXPECT_TRUE(entry_map.count(kMovedId)); | |
| 248 EXPECT_TRUE(entry_map.count(kDestId)); | |
| 249 EXPECT_EQ(kDestId, parent_resource_id_map[kMovedId]); | |
| 250 | 252 |
| 251 // Apply the changelist and check the effect. | 253 // Apply the changelist and check the effect. |
| 252 EXPECT_EQ(FILE_ERROR_OK, | 254 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); |
| 253 ApplyFullResourceList(ParseChangeList(kBaseResourceListFile))); | |
| 254 std::set<base::FilePath> changed_dirs; | 255 std::set<base::FilePath> changed_dirs; |
| 255 EXPECT_EQ(FILE_ERROR_OK, | 256 EXPECT_EQ(FILE_ERROR_OK, ApplyChangeList(change_lists.Pass(), &changed_dirs)); |
| 256 ApplyChangeList(ParseChangeList(kTestJson), &changed_dirs)); | |
| 257 | 257 |
| 258 // The value is written in kTestJson. | |
| 259 EXPECT_EQ(16809, metadata_->GetLargestChangestamp()); | 258 EXPECT_EQ(16809, metadata_->GetLargestChangestamp()); |
| 260 EXPECT_FALSE(GetResourceEntry("drive/root/Directory 1")); | 259 EXPECT_FALSE(GetResourceEntry("drive/root/Directory 1")); |
| 261 EXPECT_TRUE(GetResourceEntry( | 260 EXPECT_TRUE(GetResourceEntry( |
| 262 "drive/root/Directory 2 excludeDir-test/Directory 1")); | 261 "drive/root/Directory 2 excludeDir-test/Directory 1")); |
| 263 | 262 |
| 264 EXPECT_EQ(4U, changed_dirs.size()); | 263 EXPECT_EQ(4U, changed_dirs.size()); |
| 265 EXPECT_TRUE(changed_dirs.count( | 264 EXPECT_TRUE(changed_dirs.count( |
| 266 base::FilePath::FromUTF8Unsafe("drive/root"))); | 265 base::FilePath::FromUTF8Unsafe("drive/root"))); |
| 267 EXPECT_TRUE(changed_dirs.count( | 266 EXPECT_TRUE(changed_dirs.count( |
| 268 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); | 267 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); |
| 269 EXPECT_TRUE(changed_dirs.count( | 268 EXPECT_TRUE(changed_dirs.count( |
| 270 base::FilePath::FromUTF8Unsafe( | 269 base::FilePath::FromUTF8Unsafe( |
| 271 "drive/root/Directory 2 excludeDir-test"))); | 270 "drive/root/Directory 2 excludeDir-test"))); |
| 272 EXPECT_TRUE(changed_dirs.count( | 271 EXPECT_TRUE(changed_dirs.count( |
| 273 base::FilePath::FromUTF8Unsafe( | 272 base::FilePath::FromUTF8Unsafe( |
| 274 "drive/root/Directory 2 excludeDir-test/Directory 1"))); | 273 "drive/root/Directory 2 excludeDir-test/Directory 1"))); |
| 275 } | 274 } |
| 276 | 275 |
| 277 TEST_F(ChangeListProcessorTest, DeltaFileMovedFromDirectoryToRoot) { | 276 TEST_F(ChangeListProcessorTest, DeltaFileMovedFromDirectoryToRoot) { |
| 278 const char kTestJson[] = | 277 ScopedVector<ChangeList> change_lists; |
| 279 "gdata/delta_file_moved_from_directory_to_root.json"; | 278 change_lists.push_back(new ChangeList); |
| 280 | 279 |
| 281 ResourceEntryMap entry_map; | 280 ResourceEntry entry; |
| 282 ParentResourceIdMap parent_resource_id_map; | 281 entry.set_resource_id("file:subdirectory_file_1_id"); |
| 283 ConvertToMap(ParseChangeList(kTestJson), &entry_map, &parent_resource_id_map); | 282 entry.set_title("SubDirectory File 1.txt"); |
| 283 change_lists[0]->mutable_entries()->push_back(entry); |
| 284 change_lists[0]->mutable_parent_resource_ids()->push_back(kRootId); |
| 284 | 285 |
| 285 const std::string kMovedId("file:subdirectory_file_1_id"); | 286 change_lists[0]->set_largest_changestamp(16815); |
| 286 const std::string kSrcId("folder:1_folder_resource_id"); | |
| 287 | |
| 288 // Check the content of parsed ResourceEntryMap. | |
| 289 EXPECT_EQ(2U, entry_map.size()); | |
| 290 EXPECT_TRUE(entry_map.count(kMovedId)); | |
| 291 EXPECT_TRUE(entry_map.count(kSrcId)); | |
| 292 EXPECT_EQ(kRootId, parent_resource_id_map[kMovedId]); | |
| 293 | 287 |
| 294 // Apply the changelist and check the effect. | 288 // Apply the changelist and check the effect. |
| 295 EXPECT_EQ(FILE_ERROR_OK, | 289 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); |
| 296 ApplyFullResourceList(ParseChangeList(kBaseResourceListFile))); | |
| 297 std::set<base::FilePath> changed_dirs; | 290 std::set<base::FilePath> changed_dirs; |
| 298 EXPECT_EQ(FILE_ERROR_OK, | 291 EXPECT_EQ(FILE_ERROR_OK, ApplyChangeList(change_lists.Pass(), &changed_dirs)); |
| 299 ApplyChangeList(ParseChangeList(kTestJson), &changed_dirs)); | |
| 300 | 292 |
| 301 // The value is written in kTestJson. | |
| 302 EXPECT_EQ(16815, metadata_->GetLargestChangestamp()); | 293 EXPECT_EQ(16815, metadata_->GetLargestChangestamp()); |
| 303 EXPECT_FALSE(GetResourceEntry( | 294 EXPECT_FALSE(GetResourceEntry( |
| 304 "drive/root/Directory 1/SubDirectory File 1.txt")); | 295 "drive/root/Directory 1/SubDirectory File 1.txt")); |
| 305 EXPECT_TRUE(GetResourceEntry("drive/root/SubDirectory File 1.txt")); | 296 EXPECT_TRUE(GetResourceEntry("drive/root/SubDirectory File 1.txt")); |
| 306 | 297 |
| 307 EXPECT_EQ(2U, changed_dirs.size()); | 298 EXPECT_EQ(2U, changed_dirs.size()); |
| 308 EXPECT_TRUE(changed_dirs.count( | 299 EXPECT_TRUE(changed_dirs.count( |
| 309 base::FilePath::FromUTF8Unsafe("drive/root"))); | 300 base::FilePath::FromUTF8Unsafe("drive/root"))); |
| 310 EXPECT_TRUE(changed_dirs.count( | 301 EXPECT_TRUE(changed_dirs.count( |
| 311 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); | 302 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); |
| 312 } | 303 } |
| 313 | 304 |
| 314 TEST_F(ChangeListProcessorTest, DeltaFileRenamedInDirectory) { | 305 TEST_F(ChangeListProcessorTest, DeltaFileRenamedInDirectory) { |
| 315 const char kTestJson[] = | 306 ScopedVector<ChangeList> change_lists; |
| 316 "gdata/delta_file_renamed_in_directory.json"; | 307 change_lists.push_back(new ChangeList); |
| 317 | 308 |
| 318 ResourceEntryMap entry_map; | 309 ResourceEntry entry; |
| 319 ParentResourceIdMap parent_resource_id_map; | 310 entry.set_resource_id("file:subdirectory_file_1_id"); |
| 320 ConvertToMap(ParseChangeList(kTestJson), &entry_map, &parent_resource_id_map); | 311 entry.set_title("New SubDirectory File 1.txt"); |
| 312 change_lists[0]->mutable_entries()->push_back(entry); |
| 313 change_lists[0]->mutable_parent_resource_ids()->push_back( |
| 314 "folder:1_folder_resource_id"); |
| 321 | 315 |
| 322 const std::string kRenamedId("file:subdirectory_file_1_id"); | 316 change_lists[0]->set_largest_changestamp(16767); |
| 323 const std::string kParentId("folder:1_folder_resource_id"); | |
| 324 | |
| 325 // Check the content of parsed ResourceEntryMap. | |
| 326 EXPECT_EQ(2U, entry_map.size()); | |
| 327 EXPECT_TRUE(entry_map.count(kRenamedId)); | |
| 328 EXPECT_TRUE(entry_map.count(kParentId)); | |
| 329 EXPECT_EQ(kParentId, parent_resource_id_map[kRenamedId]); | |
| 330 EXPECT_EQ("New SubDirectory File 1.txt", entry_map[kRenamedId].title()); | |
| 331 | 317 |
| 332 // Apply the changelist and check the effect. | 318 // Apply the changelist and check the effect. |
| 333 EXPECT_EQ(FILE_ERROR_OK, | 319 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); |
| 334 ApplyFullResourceList(ParseChangeList(kBaseResourceListFile))); | |
| 335 std::set<base::FilePath> changed_dirs; | 320 std::set<base::FilePath> changed_dirs; |
| 336 EXPECT_EQ(FILE_ERROR_OK, | 321 EXPECT_EQ(FILE_ERROR_OK, ApplyChangeList(change_lists.Pass(), &changed_dirs)); |
| 337 ApplyChangeList(ParseChangeList(kTestJson), &changed_dirs)); | |
| 338 | 322 |
| 339 // The value is written in kTestJson. | |
| 340 EXPECT_EQ(16767, metadata_->GetLargestChangestamp()); | 323 EXPECT_EQ(16767, metadata_->GetLargestChangestamp()); |
| 341 EXPECT_FALSE(GetResourceEntry( | 324 EXPECT_FALSE(GetResourceEntry( |
| 342 "drive/root/Directory 1/SubDirectory File 1.txt")); | 325 "drive/root/Directory 1/SubDirectory File 1.txt")); |
| 343 EXPECT_TRUE(GetResourceEntry( | 326 EXPECT_TRUE(GetResourceEntry( |
| 344 "drive/root/Directory 1/New SubDirectory File 1.txt")); | 327 "drive/root/Directory 1/New SubDirectory File 1.txt")); |
| 345 | 328 |
| 346 EXPECT_EQ(2U, changed_dirs.size()); | 329 EXPECT_EQ(1U, changed_dirs.size()); |
| 347 EXPECT_TRUE(changed_dirs.count( | |
| 348 base::FilePath::FromUTF8Unsafe("drive/root"))); | |
| 349 EXPECT_TRUE(changed_dirs.count( | 330 EXPECT_TRUE(changed_dirs.count( |
| 350 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); | 331 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); |
| 351 } | 332 } |
| 352 | 333 |
| 353 TEST_F(ChangeListProcessorTest, DeltaAddAndDeleteFileInRoot) { | 334 TEST_F(ChangeListProcessorTest, DeltaAddAndDeleteFileInRoot) { |
| 354 const char kTestJsonAdd[] = | 335 // Create ChangeList to add a file. |
| 355 "gdata/delta_file_added_in_root.json"; | 336 ScopedVector<ChangeList> change_lists; |
| 356 const char kTestJsonDelete[] = | 337 change_lists.push_back(new ChangeList); |
| 357 "gdata/delta_file_deleted_in_root.json"; | |
| 358 | 338 |
| 359 const std::string kParentId(kRootId); | 339 ResourceEntry entry; |
| 360 const std::string kFileId("document:added_in_root_id"); | 340 entry.set_resource_id("document:added_in_root_id"); |
| 341 entry.set_title("Added file.txt"); |
| 342 change_lists[0]->mutable_entries()->push_back(entry); |
| 343 change_lists[0]->mutable_parent_resource_ids()->push_back(kRootId); |
| 361 | 344 |
| 362 ResourceEntryMap entry_map; | 345 change_lists[0]->set_largest_changestamp(16683); |
| 363 ParentResourceIdMap parent_resource_id_map; | |
| 364 | |
| 365 // Check the content of kTestJsonAdd. | |
| 366 ConvertToMap(ParseChangeList(kTestJsonAdd), | |
| 367 &entry_map, &parent_resource_id_map); | |
| 368 EXPECT_EQ(1U, entry_map.size()); | |
| 369 EXPECT_TRUE(entry_map.count(kFileId)); | |
| 370 EXPECT_EQ(kParentId, parent_resource_id_map[kFileId]); | |
| 371 EXPECT_EQ("Added file", entry_map[kFileId].title()); | |
| 372 EXPECT_FALSE(entry_map[kFileId].deleted()); | |
| 373 | 346 |
| 374 // Apply. | 347 // Apply. |
| 375 EXPECT_EQ(FILE_ERROR_OK, | 348 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); |
| 376 ApplyFullResourceList(ParseChangeList(kBaseResourceListFile))); | |
| 377 std::set<base::FilePath> changed_dirs; | 349 std::set<base::FilePath> changed_dirs; |
| 378 EXPECT_EQ(FILE_ERROR_OK, | 350 EXPECT_EQ(FILE_ERROR_OK, ApplyChangeList(change_lists.Pass(), &changed_dirs)); |
| 379 ApplyChangeList(ParseChangeList(kTestJsonAdd), &changed_dirs)); | |
| 380 EXPECT_EQ(16683, metadata_->GetLargestChangestamp()); | 351 EXPECT_EQ(16683, metadata_->GetLargestChangestamp()); |
| 381 EXPECT_TRUE(GetResourceEntry("drive/root/Added file.gdoc")); | 352 EXPECT_TRUE(GetResourceEntry("drive/root/Added file.txt")); |
| 382 EXPECT_EQ(1U, changed_dirs.size()); | 353 EXPECT_EQ(1U, changed_dirs.size()); |
| 383 EXPECT_TRUE(changed_dirs.count( | 354 EXPECT_TRUE(changed_dirs.count( |
| 384 base::FilePath::FromUTF8Unsafe("drive/root"))); | 355 base::FilePath::FromUTF8Unsafe("drive/root"))); |
| 385 | 356 |
| 386 // Check the content of kTestJsonDelete. | 357 // Create ChangeList to delete the file. |
| 387 entry_map.clear(); | 358 change_lists.push_back(new ChangeList); |
| 388 parent_resource_id_map.clear(); | 359 |
| 389 ConvertToMap(ParseChangeList(kTestJsonDelete), | 360 entry.set_deleted(true); |
| 390 &entry_map, &parent_resource_id_map); | 361 change_lists[0]->mutable_entries()->push_back(entry); |
| 391 EXPECT_EQ(1U, entry_map.size()); | 362 change_lists[0]->mutable_parent_resource_ids()->push_back(kRootId); |
| 392 EXPECT_TRUE(entry_map.count(kFileId)); | 363 |
| 393 EXPECT_EQ(kParentId, parent_resource_id_map[kFileId]); | 364 change_lists[0]->set_largest_changestamp(16687); |
| 394 EXPECT_EQ("Added file", entry_map[kFileId].title()); | |
| 395 EXPECT_TRUE(entry_map[kFileId].deleted()); | |
| 396 | 365 |
| 397 // Apply. | 366 // Apply. |
| 398 EXPECT_EQ(FILE_ERROR_OK, | 367 EXPECT_EQ(FILE_ERROR_OK, ApplyChangeList(change_lists.Pass(), &changed_dirs)); |
| 399 ApplyChangeList(ParseChangeList(kTestJsonDelete), &changed_dirs)); | |
| 400 EXPECT_EQ(16687, metadata_->GetLargestChangestamp()); | 368 EXPECT_EQ(16687, metadata_->GetLargestChangestamp()); |
| 401 EXPECT_FALSE(GetResourceEntry("drive/root/Added file.gdoc")); | 369 EXPECT_FALSE(GetResourceEntry("drive/root/Added file.txt")); |
| 402 EXPECT_EQ(1U, changed_dirs.size()); | 370 EXPECT_EQ(1U, changed_dirs.size()); |
| 403 EXPECT_TRUE(changed_dirs.count( | 371 EXPECT_TRUE(changed_dirs.count( |
| 404 base::FilePath::FromUTF8Unsafe("drive/root"))); | 372 base::FilePath::FromUTF8Unsafe("drive/root"))); |
| 405 } | 373 } |
| 406 | 374 |
| 407 | 375 |
| 408 TEST_F(ChangeListProcessorTest, DeltaAddAndDeleteFileFromExistingDirectory) { | 376 TEST_F(ChangeListProcessorTest, DeltaAddAndDeleteFileFromExistingDirectory) { |
| 409 const char kTestJsonAdd[] = | 377 // Create ChangeList to add a file. |
| 410 "gdata/delta_file_added_in_directory.json"; | 378 ScopedVector<ChangeList> change_lists; |
| 411 const char kTestJsonDelete[] = | 379 change_lists.push_back(new ChangeList); |
| 412 "gdata/delta_file_deleted_in_directory.json"; | |
| 413 | 380 |
| 414 const std::string kParentId("folder:1_folder_resource_id"); | 381 ResourceEntry entry; |
| 415 const std::string kFileId("document:added_in_root_id"); | 382 entry.set_resource_id("document:added_in_root_id"); |
| 383 entry.set_title("Added file.txt"); |
| 384 change_lists[0]->mutable_entries()->push_back(entry); |
| 385 change_lists[0]->mutable_parent_resource_ids()->push_back( |
| 386 "folder:1_folder_resource_id"); |
| 416 | 387 |
| 417 ResourceEntryMap entry_map; | 388 change_lists[0]->set_largest_changestamp(16730); |
| 418 ParentResourceIdMap parent_resource_id_map; | |
| 419 | |
| 420 // Check the content of kTestJsonAdd. | |
| 421 ConvertToMap(ParseChangeList(kTestJsonAdd), | |
| 422 &entry_map, &parent_resource_id_map); | |
| 423 EXPECT_EQ(2U, entry_map.size()); | |
| 424 EXPECT_TRUE(entry_map.count(kFileId)); | |
| 425 EXPECT_TRUE(entry_map.count(kParentId)); | |
| 426 EXPECT_EQ(kParentId, parent_resource_id_map[kFileId]); | |
| 427 EXPECT_EQ("Added file", entry_map[kFileId].title()); | |
| 428 EXPECT_FALSE(entry_map[kFileId].deleted()); | |
| 429 | 389 |
| 430 // Apply. | 390 // Apply. |
| 431 EXPECT_EQ(FILE_ERROR_OK, | 391 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); |
| 432 ApplyFullResourceList(ParseChangeList(kBaseResourceListFile))); | |
| 433 std::set<base::FilePath> changed_dirs; | 392 std::set<base::FilePath> changed_dirs; |
| 434 EXPECT_EQ(FILE_ERROR_OK, | 393 EXPECT_EQ(FILE_ERROR_OK, ApplyChangeList(change_lists.Pass(), &changed_dirs)); |
| 435 ApplyChangeList(ParseChangeList(kTestJsonAdd), &changed_dirs)); | |
| 436 EXPECT_EQ(16730, metadata_->GetLargestChangestamp()); | 394 EXPECT_EQ(16730, metadata_->GetLargestChangestamp()); |
| 437 EXPECT_TRUE(GetResourceEntry("drive/root/Directory 1/Added file.gdoc")); | 395 EXPECT_TRUE(GetResourceEntry("drive/root/Directory 1/Added file.txt")); |
| 438 | 396 |
| 439 EXPECT_EQ(2U, changed_dirs.size()); | 397 EXPECT_EQ(1U, changed_dirs.size()); |
| 440 EXPECT_TRUE(changed_dirs.count( | |
| 441 base::FilePath::FromUTF8Unsafe("drive/root"))); | |
| 442 EXPECT_TRUE(changed_dirs.count( | 398 EXPECT_TRUE(changed_dirs.count( |
| 443 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); | 399 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); |
| 444 | 400 |
| 445 // Check the content of kTestJsonDelete. | 401 // Create ChangeList to delete the file. |
| 446 entry_map.clear(); | 402 change_lists.push_back(new ChangeList); |
| 447 parent_resource_id_map.clear(); | 403 |
| 448 ConvertToMap(ParseChangeList(kTestJsonDelete), | 404 entry.set_deleted(true); |
| 449 &entry_map, &parent_resource_id_map); | 405 change_lists[0]->mutable_entries()->push_back(entry); |
| 450 EXPECT_EQ(1U, entry_map.size()); | 406 change_lists[0]->mutable_parent_resource_ids()->push_back( |
| 451 EXPECT_TRUE(entry_map.count(kFileId)); | 407 "folder:1_folder_resource_id"); |
| 452 EXPECT_EQ(kParentId, parent_resource_id_map[kFileId]); | 408 |
| 453 EXPECT_EQ("Added file", entry_map[kFileId].title()); | 409 change_lists[0]->set_largest_changestamp(16770); |
| 454 EXPECT_TRUE(entry_map[kFileId].deleted()); | |
| 455 | 410 |
| 456 // Apply. | 411 // Apply. |
| 457 EXPECT_EQ(FILE_ERROR_OK, | 412 EXPECT_EQ(FILE_ERROR_OK, ApplyChangeList(change_lists.Pass(), &changed_dirs)); |
| 458 ApplyChangeList(ParseChangeList(kTestJsonDelete), &changed_dirs)); | |
| 459 EXPECT_EQ(16770, metadata_->GetLargestChangestamp()); | 413 EXPECT_EQ(16770, metadata_->GetLargestChangestamp()); |
| 460 EXPECT_FALSE(GetResourceEntry("drive/root/Directory 1/Added file.gdoc")); | 414 EXPECT_FALSE(GetResourceEntry("drive/root/Directory 1/Added file.txt")); |
| 461 | 415 |
| 462 EXPECT_EQ(1U, changed_dirs.size()); | 416 EXPECT_EQ(1U, changed_dirs.size()); |
| 463 EXPECT_TRUE(changed_dirs.count( | 417 EXPECT_TRUE(changed_dirs.count( |
| 464 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); | 418 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1"))); |
| 465 } | 419 } |
| 466 | 420 |
| 467 TEST_F(ChangeListProcessorTest, DeltaAddFileToNewButDeletedDirectory) { | 421 TEST_F(ChangeListProcessorTest, DeltaAddFileToNewButDeletedDirectory) { |
| 468 // This file contains the following updates: | 422 // Create a change which contains the following updates: |
| 469 // 1) A new PDF file is added to a new directory | 423 // 1) A new PDF file is added to a new directory |
| 470 // 2) but the new directory is marked "deleted" (i.e. moved to Trash) | 424 // 2) but the new directory is marked "deleted" (i.e. moved to Trash) |
| 471 // Hence, the PDF file should be just ignored. | 425 // Hence, the PDF file should be just ignored. |
| 472 const char kTestJson[] = | 426 ScopedVector<ChangeList> change_lists; |
| 473 "gdata/delta_file_added_in_new_but_deleted_directory.json"; | 427 change_lists.push_back(new ChangeList); |
| 474 | 428 |
| 475 ResourceEntryMap entry_map; | 429 ResourceEntry file; |
| 476 ParentResourceIdMap parent_resource_id_map; | 430 file.set_resource_id("pdf:file_added_in_deleted_id"); |
| 477 ConvertToMap(ParseChangeList(kTestJson), &entry_map, &parent_resource_id_map); | 431 file.set_title("new_pdf_file.pdf"); |
| 432 file.set_deleted(true); |
| 433 change_lists[0]->mutable_entries()->push_back(file); |
| 434 change_lists[0]->mutable_parent_resource_ids()->push_back( |
| 435 "folder:new_folder_resource_id"); |
| 478 | 436 |
| 479 const std::string kDirId("folder:new_folder_resource_id"); | 437 ResourceEntry directory; |
| 480 const std::string kFileId("pdf:file_added_in_deleted_dir_id"); | 438 directory.set_resource_id("folder:new_folder_resource_id"); |
| 439 directory.set_title("New Directory"); |
| 440 directory.mutable_file_info()->set_is_directory(true); |
| 441 directory.set_deleted(true); |
| 442 change_lists[0]->mutable_entries()->push_back(directory); |
| 443 change_lists[0]->mutable_parent_resource_ids()->push_back(kRootId); |
| 481 | 444 |
| 482 // Check the content of parsed ResourceEntryMap. | 445 change_lists[0]->set_largest_changestamp(16730); |
| 483 EXPECT_EQ(2U, entry_map.size()); | |
| 484 EXPECT_TRUE(entry_map.count(kDirId)); | |
| 485 EXPECT_TRUE(entry_map.count(kFileId)); | |
| 486 EXPECT_EQ(kDirId, parent_resource_id_map[kFileId]); | |
| 487 EXPECT_TRUE(entry_map[kDirId].deleted()); | |
| 488 | 446 |
| 489 // Apply the changelist and check the effect. | 447 // Apply the changelist and check the effect. |
| 490 EXPECT_EQ(FILE_ERROR_OK, | 448 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); |
| 491 ApplyFullResourceList(ParseChangeList(kBaseResourceListFile))); | |
| 492 std::set<base::FilePath> changed_dirs; | 449 std::set<base::FilePath> changed_dirs; |
| 493 EXPECT_EQ(FILE_ERROR_OK, | 450 EXPECT_EQ(FILE_ERROR_OK, ApplyChangeList(change_lists.Pass(), &changed_dirs)); |
| 494 ApplyChangeList(ParseChangeList(kTestJson), &changed_dirs)); | |
| 495 | 451 |
| 496 // The value is written in kTestJson. | |
| 497 EXPECT_EQ(16730, metadata_->GetLargestChangestamp()); | 452 EXPECT_EQ(16730, metadata_->GetLargestChangestamp()); |
| 498 EXPECT_FALSE(GetResourceEntry("drive/root/New Directory/new_pdf_file.pdf")); | 453 EXPECT_FALSE(GetResourceEntry("drive/root/New Directory/new_pdf_file.pdf")); |
| 499 | 454 |
| 500 EXPECT_TRUE(changed_dirs.empty()); | 455 EXPECT_TRUE(changed_dirs.empty()); |
| 501 } | 456 } |
| 502 | 457 |
| 503 TEST_F(ChangeListProcessorTest, RefreshDirectory) { | 458 TEST_F(ChangeListProcessorTest, RefreshDirectory) { |
| 504 // Prepare metadata. | 459 // Prepare metadata. |
| 505 EXPECT_EQ(FILE_ERROR_OK, | 460 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); |
| 506 ApplyFullResourceList(ParseChangeList(kBaseResourceListFile))); | |
| 507 | 461 |
| 508 // Create change list. | 462 // Create change list. |
| 509 scoped_ptr<ChangeList> change_list(new ChangeList); | 463 scoped_ptr<ChangeList> change_list(new ChangeList); |
| 510 | 464 |
| 511 // Add a new file to the change list. | 465 // Add a new file to the change list. |
| 512 ResourceEntry new_file; | 466 ResourceEntry new_file; |
| 513 new_file.set_title("new_file"); | 467 new_file.set_title("new_file"); |
| 514 new_file.set_resource_id("new_file_id"); | 468 new_file.set_resource_id("new_file_id"); |
| 515 change_list->mutable_entries()->push_back(new_file); | 469 change_list->mutable_entries()->push_back(new_file); |
| 516 change_list->mutable_parent_resource_ids()->push_back(kRootId); | 470 change_list->mutable_parent_resource_ids()->push_back(kRootId); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 540 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryByPath( | 494 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryByPath( |
| 541 util::GetDriveMyDriveRootPath().AppendASCII(new_file.title()), &entry)); | 495 util::GetDriveMyDriveRootPath().AppendASCII(new_file.title()), &entry)); |
| 542 | 496 |
| 543 // "Directory 1" should be renamed. | 497 // "Directory 1" should be renamed. |
| 544 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryByPath( | 498 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryByPath( |
| 545 util::GetDriveMyDriveRootPath().AppendASCII(dir1.title()), &entry)); | 499 util::GetDriveMyDriveRootPath().AppendASCII(dir1.title()), &entry)); |
| 546 } | 500 } |
| 547 | 501 |
| 548 TEST_F(ChangeListProcessorTest, RefreshDirectory_WrongParentId) { | 502 TEST_F(ChangeListProcessorTest, RefreshDirectory_WrongParentId) { |
| 549 // Prepare metadata. | 503 // Prepare metadata. |
| 550 EXPECT_EQ(FILE_ERROR_OK, | 504 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); |
| 551 ApplyFullResourceList(ParseChangeList(kBaseResourceListFile))); | |
| 552 | 505 |
| 553 // Create change list and add a new file to it. | 506 // Create change list and add a new file to it. |
| 554 scoped_ptr<ChangeList> change_list(new ChangeList); | 507 scoped_ptr<ChangeList> change_list(new ChangeList); |
| 555 ResourceEntry new_file; | 508 ResourceEntry new_file; |
| 556 new_file.set_title("new_file"); | 509 new_file.set_title("new_file"); |
| 557 new_file.set_resource_id("new_file_id"); | 510 new_file.set_resource_id("new_file_id"); |
| 558 // This entry should not be added because the parent ID does not match. | 511 // This entry should not be added because the parent ID does not match. |
| 559 change_list->mutable_parent_resource_ids()->push_back( | 512 change_list->mutable_parent_resource_ids()->push_back( |
| 560 "some-random-resource-id"); | 513 "some-random-resource-id"); |
| 561 change_list->mutable_entries()->push_back(new_file); | 514 change_list->mutable_entries()->push_back(new_file); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 574 &refreshed_entries)); | 527 &refreshed_entries)); |
| 575 | 528 |
| 576 // "new_file" should not be added. | 529 // "new_file" should not be added. |
| 577 ResourceEntry entry; | 530 ResourceEntry entry; |
| 578 EXPECT_EQ(FILE_ERROR_NOT_FOUND, metadata_->GetResourceEntryByPath( | 531 EXPECT_EQ(FILE_ERROR_NOT_FOUND, metadata_->GetResourceEntryByPath( |
| 579 util::GetDriveMyDriveRootPath().AppendASCII(new_file.title()), &entry)); | 532 util::GetDriveMyDriveRootPath().AppendASCII(new_file.title()), &entry)); |
| 580 } | 533 } |
| 581 | 534 |
| 582 TEST_F(ChangeListProcessorTest, SharedFilesWithNoParentInFeed) { | 535 TEST_F(ChangeListProcessorTest, SharedFilesWithNoParentInFeed) { |
| 583 // Prepare metadata. | 536 // Prepare metadata. |
| 584 EXPECT_EQ(FILE_ERROR_OK, | 537 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); |
| 585 ApplyFullResourceList(ParseChangeList(kBaseResourceListFile))); | |
| 586 | 538 |
| 587 // Create change lists. | 539 // Create change lists. |
| 588 ScopedVector<ChangeList> change_lists; | 540 ScopedVector<ChangeList> change_lists; |
| 589 change_lists.push_back(new ChangeList); | 541 change_lists.push_back(new ChangeList); |
| 590 | 542 |
| 591 // Add a new file with non-existing parent resource id to the change lists. | 543 // Add a new file with non-existing parent resource id to the change lists. |
| 592 ResourceEntry new_file; | 544 ResourceEntry new_file; |
| 593 new_file.set_title("new_file"); | 545 new_file.set_title("new_file"); |
| 594 new_file.set_resource_id("new_file_id"); | 546 new_file.set_resource_id("new_file_id"); |
| 595 change_lists[0]->mutable_entries()->push_back(new_file); | 547 change_lists[0]->mutable_entries()->push_back(new_file); |
| 596 change_lists[0]->mutable_parent_resource_ids()->push_back("nonexisting"); | 548 change_lists[0]->mutable_parent_resource_ids()->push_back("nonexisting"); |
| 597 change_lists[0]->set_largest_changestamp(kBaseResourceListChangestamp + 1); | 549 change_lists[0]->set_largest_changestamp(kBaseResourceListChangestamp + 1); |
| 598 | 550 |
| 599 std::set<base::FilePath> changed_dirs; | 551 std::set<base::FilePath> changed_dirs; |
| 600 EXPECT_EQ(FILE_ERROR_OK, ApplyChangeList(change_lists.Pass(), &changed_dirs)); | 552 EXPECT_EQ(FILE_ERROR_OK, ApplyChangeList(change_lists.Pass(), &changed_dirs)); |
| 601 | 553 |
| 602 // "new_file" should be added under drive/other. | 554 // "new_file" should be added under drive/other. |
| 603 ResourceEntry entry; | 555 ResourceEntry entry; |
| 604 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryByPath( | 556 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryByPath( |
| 605 util::GetDriveGrandRootPath().AppendASCII("other/new_file"), &entry)); | 557 util::GetDriveGrandRootPath().AppendASCII("other/new_file"), &entry)); |
| 606 } | 558 } |
| 607 | 559 |
| 608 TEST_F(ChangeListProcessorTest, ModificationDate) { | 560 TEST_F(ChangeListProcessorTest, ModificationDate) { |
| 609 // Prepare metadata. | 561 // Prepare metadata. |
| 610 EXPECT_EQ(FILE_ERROR_OK, | 562 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); |
| 611 ApplyFullResourceList(ParseChangeList(kBaseResourceListFile))); | |
| 612 | 563 |
| 613 // Create change lists with a new file. | 564 // Create change lists with a new file. |
| 614 ScopedVector<ChangeList> change_lists; | 565 ScopedVector<ChangeList> change_lists; |
| 615 change_lists.push_back(new ChangeList); | 566 change_lists.push_back(new ChangeList); |
| 616 | 567 |
| 617 const base::Time now = base::Time::Now(); | 568 const base::Time now = base::Time::Now(); |
| 618 ResourceEntry new_file_remote; | 569 ResourceEntry new_file_remote; |
| 619 new_file_remote.set_title("new_file_remote"); | 570 new_file_remote.set_title("new_file_remote"); |
| 620 new_file_remote.set_resource_id("new_file_id"); | 571 new_file_remote.set_resource_id("new_file_id"); |
| 621 new_file_remote.set_modification_date(now.ToInternalValue()); | 572 new_file_remote.set_modification_date(now.ToInternalValue()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 645 EXPECT_EQ(FILE_ERROR_OK, ApplyChangeList(change_lists.Pass(), &changed_dirs)); | 596 EXPECT_EQ(FILE_ERROR_OK, ApplyChangeList(change_lists.Pass(), &changed_dirs)); |
| 646 | 597 |
| 647 // The change is rejected due to the old modification date. | 598 // The change is rejected due to the old modification date. |
| 648 ResourceEntry entry; | 599 ResourceEntry entry; |
| 649 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryById(local_id, &entry)); | 600 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryById(local_id, &entry)); |
| 650 EXPECT_EQ(new_file_local.title(), entry.title()); | 601 EXPECT_EQ(new_file_local.title(), entry.title()); |
| 651 } | 602 } |
| 652 | 603 |
| 653 } // namespace internal | 604 } // namespace internal |
| 654 } // namespace drive | 605 } // namespace drive |
| OLD | NEW |