Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: components/drive/change_list_processor_unittest.cc

Issue 1552023002: Convert Pass()→std::move() in //components (CrOS edition) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "components/drive/change_list_processor.h" 5 #include "components/drive/change_list_processor.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility>
9 10
10 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
13 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 #include "components/drive/drive.pb.h" 16 #include "components/drive/drive.pb.h"
16 #include "components/drive/drive_test_util.h" 17 #include "components/drive/drive_test_util.h"
17 #include "components/drive/fake_free_disk_space_getter.h" 18 #include "components/drive/fake_free_disk_space_getter.h"
18 #include "components/drive/file_cache.h" 19 #include "components/drive/file_cache.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 change_lists[0]->mutable_entries()->push_back(file); 92 change_lists[0]->mutable_entries()->push_back(file);
92 change_lists[0]->mutable_parent_resource_ids()->push_back( 93 change_lists[0]->mutable_parent_resource_ids()->push_back(
93 "1_folder_resource_id"); 94 "1_folder_resource_id");
94 95
95 file.set_title("Orphan File 1.txt"); 96 file.set_title("Orphan File 1.txt");
96 file.set_resource_id("1_orphanfile_resource_id"); 97 file.set_resource_id("1_orphanfile_resource_id");
97 change_lists[0]->mutable_entries()->push_back(file); 98 change_lists[0]->mutable_entries()->push_back(file);
98 change_lists[0]->mutable_parent_resource_ids()->push_back(""); 99 change_lists[0]->mutable_parent_resource_ids()->push_back("");
99 100
100 change_lists[0]->set_largest_changestamp(kBaseResourceListChangestamp); 101 change_lists[0]->set_largest_changestamp(kBaseResourceListChangestamp);
101 return change_lists.Pass(); 102 return change_lists;
102 } 103 }
103 104
104 class ChangeListProcessorTest : public testing::Test { 105 class ChangeListProcessorTest : public testing::Test {
105 protected: 106 protected:
106 void SetUp() override { 107 void SetUp() override {
107 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 108 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
108 109
109 metadata_storage_.reset(new ResourceMetadataStorage( 110 metadata_storage_.reset(new ResourceMetadataStorage(
110 temp_dir_.path(), base::ThreadTaskRunnerHandle::Get().get())); 111 temp_dir_.path(), base::ThreadTaskRunnerHandle::Get().get()));
111 ASSERT_TRUE(metadata_storage_->Initialize()); 112 ASSERT_TRUE(metadata_storage_->Initialize());
(...skipping 13 matching lines...) Expand all
125 126
126 // Applies the |changes| to |metadata_| as a full resource list of changestamp 127 // Applies the |changes| to |metadata_| as a full resource list of changestamp
127 // |kBaseResourceListChangestamp|. 128 // |kBaseResourceListChangestamp|.
128 FileError ApplyFullResourceList(ScopedVector<ChangeList> changes) { 129 FileError ApplyFullResourceList(ScopedVector<ChangeList> changes) {
129 scoped_ptr<google_apis::AboutResource> about_resource( 130 scoped_ptr<google_apis::AboutResource> about_resource(
130 new google_apis::AboutResource); 131 new google_apis::AboutResource);
131 about_resource->set_largest_change_id(kBaseResourceListChangestamp); 132 about_resource->set_largest_change_id(kBaseResourceListChangestamp);
132 about_resource->set_root_folder_id(kRootId); 133 about_resource->set_root_folder_id(kRootId);
133 134
134 ChangeListProcessor processor(metadata_.get(), nullptr); 135 ChangeListProcessor processor(metadata_.get(), nullptr);
135 return processor.Apply(about_resource.Pass(), 136 return processor.Apply(std::move(about_resource), std::move(changes),
136 changes.Pass(),
137 false /* is_delta_update */); 137 false /* is_delta_update */);
138 } 138 }
139 139
140 // Applies the |changes| to |metadata_| as a delta update. Delta changelists 140 // Applies the |changes| to |metadata_| as a delta update. Delta changelists
141 // should contain their changestamp in themselves. 141 // should contain their changestamp in themselves.
142 FileError ApplyChangeList(ScopedVector<ChangeList> changes, 142 FileError ApplyChangeList(ScopedVector<ChangeList> changes,
143 FileChange* changed_files) { 143 FileChange* changed_files) {
144 scoped_ptr<google_apis::AboutResource> about_resource( 144 scoped_ptr<google_apis::AboutResource> about_resource(
145 new google_apis::AboutResource); 145 new google_apis::AboutResource);
146 about_resource->set_largest_change_id(kBaseResourceListChangestamp); 146 about_resource->set_largest_change_id(kBaseResourceListChangestamp);
147 about_resource->set_root_folder_id(kRootId); 147 about_resource->set_root_folder_id(kRootId);
148 148
149 ChangeListProcessor processor(metadata_.get(), nullptr); 149 ChangeListProcessor processor(metadata_.get(), nullptr);
150 FileError error = processor.Apply(about_resource.Pass(), 150 FileError error =
151 changes.Pass(), 151 processor.Apply(std::move(about_resource), std::move(changes),
152 true /* is_delta_update */); 152 true /* is_delta_update */);
153 *changed_files = processor.changed_files(); 153 *changed_files = processor.changed_files();
154 return error; 154 return error;
155 } 155 }
156 156
157 // Gets the resource entry for the path from |metadata_| synchronously. 157 // Gets the resource entry for the path from |metadata_| synchronously.
158 // Returns null if the entry does not exist. 158 // Returns null if the entry does not exist.
159 scoped_ptr<ResourceEntry> GetResourceEntry(const std::string& path) { 159 scoped_ptr<ResourceEntry> GetResourceEntry(const std::string& path) {
160 scoped_ptr<ResourceEntry> entry(new ResourceEntry); 160 scoped_ptr<ResourceEntry> entry(new ResourceEntry);
161 FileError error = metadata_->GetResourceEntryByPath( 161 FileError error = metadata_->GetResourceEntryByPath(
162 base::FilePath::FromUTF8Unsafe(path), entry.get()); 162 base::FilePath::FromUTF8Unsafe(path), entry.get());
163 if (error != FILE_ERROR_OK) 163 if (error != FILE_ERROR_OK)
164 entry.reset(); 164 entry.reset();
165 return entry.Pass(); 165 return entry;
166 } 166 }
167 167
168 content::TestBrowserThreadBundle thread_bundle_; 168 content::TestBrowserThreadBundle thread_bundle_;
169 base::ScopedTempDir temp_dir_; 169 base::ScopedTempDir temp_dir_;
170 scoped_ptr<ResourceMetadataStorage, 170 scoped_ptr<ResourceMetadataStorage,
171 test_util::DestroyHelperForTests> metadata_storage_; 171 test_util::DestroyHelperForTests> metadata_storage_;
172 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_; 172 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_;
173 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_; 173 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_;
174 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> metadata_; 174 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> metadata_;
175 }; 175 };
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 change_lists[0]->mutable_parent_resource_ids()->push_back( 239 change_lists[0]->mutable_parent_resource_ids()->push_back(
240 new_folder.resource_id()); 240 new_folder.resource_id());
241 241
242 change_lists[0]->set_largest_changestamp(16730); 242 change_lists[0]->set_largest_changestamp(16730);
243 243
244 // Apply the changelist and check the effect. 244 // Apply the changelist and check the effect.
245 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); 245 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList()));
246 246
247 FileChange changed_files; 247 FileChange changed_files;
248 EXPECT_EQ(FILE_ERROR_OK, 248 EXPECT_EQ(FILE_ERROR_OK,
249 ApplyChangeList(change_lists.Pass(), &changed_files)); 249 ApplyChangeList(std::move(change_lists), &changed_files));
250 250
251 int64_t changestamp = 0; 251 int64_t changestamp = 0;
252 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); 252 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp));
253 EXPECT_EQ(16730, changestamp); 253 EXPECT_EQ(16730, changestamp);
254 EXPECT_TRUE(GetResourceEntry("drive/root/New Directory")); 254 EXPECT_TRUE(GetResourceEntry("drive/root/New Directory"));
255 EXPECT_TRUE(GetResourceEntry( 255 EXPECT_TRUE(GetResourceEntry(
256 "drive/root/New Directory/File in new dir.txt")); 256 "drive/root/New Directory/File in new dir.txt"));
257 257
258 EXPECT_EQ(2U, changed_files.size()); 258 EXPECT_EQ(2U, changed_files.size());
259 EXPECT_TRUE(changed_files.count(base::FilePath::FromUTF8Unsafe( 259 EXPECT_TRUE(changed_files.count(base::FilePath::FromUTF8Unsafe(
(...skipping 14 matching lines...) Expand all
274 change_lists[0]->mutable_parent_resource_ids()->push_back( 274 change_lists[0]->mutable_parent_resource_ids()->push_back(
275 "sub_dir_folder_2_self_link"); 275 "sub_dir_folder_2_self_link");
276 276
277 change_lists[0]->set_largest_changestamp(16809); 277 change_lists[0]->set_largest_changestamp(16809);
278 278
279 // Apply the changelist and check the effect. 279 // Apply the changelist and check the effect.
280 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); 280 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList()));
281 281
282 FileChange changed_files; 282 FileChange changed_files;
283 EXPECT_EQ(FILE_ERROR_OK, 283 EXPECT_EQ(FILE_ERROR_OK,
284 ApplyChangeList(change_lists.Pass(), &changed_files)); 284 ApplyChangeList(std::move(change_lists), &changed_files));
285 285
286 int64_t changestamp = 0; 286 int64_t changestamp = 0;
287 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); 287 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp));
288 EXPECT_EQ(16809, changestamp); 288 EXPECT_EQ(16809, changestamp);
289 EXPECT_FALSE(GetResourceEntry("drive/root/Directory 1")); 289 EXPECT_FALSE(GetResourceEntry("drive/root/Directory 1"));
290 EXPECT_TRUE(GetResourceEntry( 290 EXPECT_TRUE(GetResourceEntry(
291 "drive/root/Directory 2 excludeDir-test/Directory 1")); 291 "drive/root/Directory 2 excludeDir-test/Directory 1"));
292 292
293 EXPECT_EQ(2U, changed_files.size()); 293 EXPECT_EQ(2U, changed_files.size());
294 EXPECT_TRUE(changed_files.CountDirectory( 294 EXPECT_TRUE(changed_files.CountDirectory(
(...skipping 15 matching lines...) Expand all
310 entry.set_title("SubDirectory File 1.txt"); 310 entry.set_title("SubDirectory File 1.txt");
311 change_lists[0]->mutable_entries()->push_back(entry); 311 change_lists[0]->mutable_entries()->push_back(entry);
312 change_lists[0]->mutable_parent_resource_ids()->push_back(kRootId); 312 change_lists[0]->mutable_parent_resource_ids()->push_back(kRootId);
313 313
314 change_lists[0]->set_largest_changestamp(16815); 314 change_lists[0]->set_largest_changestamp(16815);
315 315
316 // Apply the changelist and check the effect. 316 // Apply the changelist and check the effect.
317 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); 317 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList()));
318 FileChange changed_files; 318 FileChange changed_files;
319 EXPECT_EQ(FILE_ERROR_OK, 319 EXPECT_EQ(FILE_ERROR_OK,
320 ApplyChangeList(change_lists.Pass(), &changed_files)); 320 ApplyChangeList(std::move(change_lists), &changed_files));
321 321
322 int64_t changestamp = 0; 322 int64_t changestamp = 0;
323 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); 323 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp));
324 EXPECT_EQ(16815, changestamp); 324 EXPECT_EQ(16815, changestamp);
325 EXPECT_FALSE(GetResourceEntry( 325 EXPECT_FALSE(GetResourceEntry(
326 "drive/root/Directory 1/SubDirectory File 1.txt")); 326 "drive/root/Directory 1/SubDirectory File 1.txt"));
327 EXPECT_TRUE(GetResourceEntry("drive/root/SubDirectory File 1.txt")); 327 EXPECT_TRUE(GetResourceEntry("drive/root/SubDirectory File 1.txt"));
328 328
329 EXPECT_EQ(2U, changed_files.size()); 329 EXPECT_EQ(2U, changed_files.size());
330 EXPECT_TRUE(changed_files.count( 330 EXPECT_TRUE(changed_files.count(
(...skipping 12 matching lines...) Expand all
343 change_lists[0]->mutable_entries()->push_back(entry); 343 change_lists[0]->mutable_entries()->push_back(entry);
344 change_lists[0]->mutable_parent_resource_ids()->push_back( 344 change_lists[0]->mutable_parent_resource_ids()->push_back(
345 "1_folder_resource_id"); 345 "1_folder_resource_id");
346 346
347 change_lists[0]->set_largest_changestamp(16767); 347 change_lists[0]->set_largest_changestamp(16767);
348 348
349 // Apply the changelist and check the effect. 349 // Apply the changelist and check the effect.
350 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); 350 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList()));
351 FileChange changed_files; 351 FileChange changed_files;
352 EXPECT_EQ(FILE_ERROR_OK, 352 EXPECT_EQ(FILE_ERROR_OK,
353 ApplyChangeList(change_lists.Pass(), &changed_files)); 353 ApplyChangeList(std::move(change_lists), &changed_files));
354 EXPECT_EQ(2U, changed_files.size()); 354 EXPECT_EQ(2U, changed_files.size());
355 EXPECT_TRUE(changed_files.count(base::FilePath::FromUTF8Unsafe( 355 EXPECT_TRUE(changed_files.count(base::FilePath::FromUTF8Unsafe(
356 "drive/root/Directory 1/SubDirectory File 1.txt"))); 356 "drive/root/Directory 1/SubDirectory File 1.txt")));
357 EXPECT_TRUE(changed_files.count(base::FilePath::FromUTF8Unsafe( 357 EXPECT_TRUE(changed_files.count(base::FilePath::FromUTF8Unsafe(
358 "drive/root/Directory 1/New SubDirectory File 1.txt"))); 358 "drive/root/Directory 1/New SubDirectory File 1.txt")));
359 359
360 int64_t changestamp = 0; 360 int64_t changestamp = 0;
361 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); 361 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp));
362 EXPECT_EQ(16767, changestamp); 362 EXPECT_EQ(16767, changestamp);
363 EXPECT_FALSE(GetResourceEntry( 363 EXPECT_FALSE(GetResourceEntry(
(...skipping 18 matching lines...) Expand all
382 entry.set_title("Added file.txt"); 382 entry.set_title("Added file.txt");
383 change_lists[0]->mutable_entries()->push_back(entry); 383 change_lists[0]->mutable_entries()->push_back(entry);
384 change_lists[0]->mutable_parent_resource_ids()->push_back(kRootId); 384 change_lists[0]->mutable_parent_resource_ids()->push_back(kRootId);
385 385
386 change_lists[0]->set_largest_changestamp(16683); 386 change_lists[0]->set_largest_changestamp(16683);
387 387
388 // Apply. 388 // Apply.
389 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); 389 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList()));
390 FileChange changed_files; 390 FileChange changed_files;
391 EXPECT_EQ(FILE_ERROR_OK, 391 EXPECT_EQ(FILE_ERROR_OK,
392 ApplyChangeList(change_lists.Pass(), &changed_files)); 392 ApplyChangeList(std::move(change_lists), &changed_files));
393 393
394 int64_t changestamp = 0; 394 int64_t changestamp = 0;
395 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); 395 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp));
396 EXPECT_EQ(16683, changestamp); 396 EXPECT_EQ(16683, changestamp);
397 EXPECT_TRUE(GetResourceEntry("drive/root/Added file.txt")); 397 EXPECT_TRUE(GetResourceEntry("drive/root/Added file.txt"));
398 EXPECT_EQ(1U, changed_files.size()); 398 EXPECT_EQ(1U, changed_files.size());
399 EXPECT_TRUE(changed_files.count( 399 EXPECT_TRUE(changed_files.count(
400 base::FilePath::FromUTF8Unsafe("drive/root/Added file.txt"))); 400 base::FilePath::FromUTF8Unsafe("drive/root/Added file.txt")));
401 401
402 // Create ChangeList to delete the file. 402 // Create ChangeList to delete the file.
403 change_lists.push_back(new ChangeList); 403 change_lists.push_back(new ChangeList);
404 404
405 entry.set_deleted(true); 405 entry.set_deleted(true);
406 change_lists[0]->mutable_entries()->push_back(entry); 406 change_lists[0]->mutable_entries()->push_back(entry);
407 change_lists[0]->mutable_parent_resource_ids()->push_back(kRootId); 407 change_lists[0]->mutable_parent_resource_ids()->push_back(kRootId);
408 408
409 change_lists[0]->set_largest_changestamp(16687); 409 change_lists[0]->set_largest_changestamp(16687);
410 410
411 // Apply. 411 // Apply.
412 EXPECT_EQ(FILE_ERROR_OK, 412 EXPECT_EQ(FILE_ERROR_OK,
413 ApplyChangeList(change_lists.Pass(), &changed_files)); 413 ApplyChangeList(std::move(change_lists), &changed_files));
414 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); 414 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp));
415 EXPECT_EQ(16687, changestamp); 415 EXPECT_EQ(16687, changestamp);
416 EXPECT_FALSE(GetResourceEntry("drive/root/Added file.txt")); 416 EXPECT_FALSE(GetResourceEntry("drive/root/Added file.txt"));
417 EXPECT_EQ(1U, changed_files.size()); 417 EXPECT_EQ(1U, changed_files.size());
418 EXPECT_TRUE(changed_files.count( 418 EXPECT_TRUE(changed_files.count(
419 base::FilePath::FromUTF8Unsafe("drive/root/Added file.txt"))); 419 base::FilePath::FromUTF8Unsafe("drive/root/Added file.txt")));
420 } 420 }
421 421
422 422
423 TEST_F(ChangeListProcessorTest, DeltaAddAndDeleteFileFromExistingDirectory) { 423 TEST_F(ChangeListProcessorTest, DeltaAddAndDeleteFileFromExistingDirectory) {
424 // Create ChangeList to add a file. 424 // Create ChangeList to add a file.
425 ScopedVector<ChangeList> change_lists; 425 ScopedVector<ChangeList> change_lists;
426 change_lists.push_back(new ChangeList); 426 change_lists.push_back(new ChangeList);
427 427
428 ResourceEntry entry; 428 ResourceEntry entry;
429 entry.set_resource_id("added_in_root_id"); 429 entry.set_resource_id("added_in_root_id");
430 entry.set_title("Added file.txt"); 430 entry.set_title("Added file.txt");
431 change_lists[0]->mutable_entries()->push_back(entry); 431 change_lists[0]->mutable_entries()->push_back(entry);
432 change_lists[0]->mutable_parent_resource_ids()->push_back( 432 change_lists[0]->mutable_parent_resource_ids()->push_back(
433 "1_folder_resource_id"); 433 "1_folder_resource_id");
434 434
435 change_lists[0]->set_largest_changestamp(16730); 435 change_lists[0]->set_largest_changestamp(16730);
436 436
437 // Apply. 437 // Apply.
438 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); 438 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList()));
439 FileChange changed_files; 439 FileChange changed_files;
440 EXPECT_EQ(FILE_ERROR_OK, 440 EXPECT_EQ(FILE_ERROR_OK,
441 ApplyChangeList(change_lists.Pass(), &changed_files)); 441 ApplyChangeList(std::move(change_lists), &changed_files));
442 int64_t changestamp = 0; 442 int64_t changestamp = 0;
443 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); 443 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp));
444 EXPECT_EQ(16730, changestamp); 444 EXPECT_EQ(16730, changestamp);
445 EXPECT_TRUE(GetResourceEntry("drive/root/Directory 1/Added file.txt")); 445 EXPECT_TRUE(GetResourceEntry("drive/root/Directory 1/Added file.txt"));
446 446
447 EXPECT_EQ(1U, changed_files.size()); 447 EXPECT_EQ(1U, changed_files.size());
448 EXPECT_TRUE(changed_files.count( 448 EXPECT_TRUE(changed_files.count(
449 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1/Added file.txt"))); 449 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1/Added file.txt")));
450 450
451 // Create ChangeList to delete the file. 451 // Create ChangeList to delete the file.
452 change_lists.push_back(new ChangeList); 452 change_lists.push_back(new ChangeList);
453 453
454 entry.set_deleted(true); 454 entry.set_deleted(true);
455 change_lists[0]->mutable_entries()->push_back(entry); 455 change_lists[0]->mutable_entries()->push_back(entry);
456 change_lists[0]->mutable_parent_resource_ids()->push_back( 456 change_lists[0]->mutable_parent_resource_ids()->push_back(
457 "1_folder_resource_id"); 457 "1_folder_resource_id");
458 458
459 change_lists[0]->set_largest_changestamp(16770); 459 change_lists[0]->set_largest_changestamp(16770);
460 460
461 // Apply. 461 // Apply.
462 EXPECT_EQ(FILE_ERROR_OK, 462 EXPECT_EQ(FILE_ERROR_OK,
463 ApplyChangeList(change_lists.Pass(), &changed_files)); 463 ApplyChangeList(std::move(change_lists), &changed_files));
464 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); 464 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp));
465 EXPECT_EQ(16770, changestamp); 465 EXPECT_EQ(16770, changestamp);
466 EXPECT_FALSE(GetResourceEntry("drive/root/Directory 1/Added file.txt")); 466 EXPECT_FALSE(GetResourceEntry("drive/root/Directory 1/Added file.txt"));
467 467
468 EXPECT_EQ(1U, changed_files.size()); 468 EXPECT_EQ(1U, changed_files.size());
469 EXPECT_TRUE(changed_files.count( 469 EXPECT_TRUE(changed_files.count(
470 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1/Added file.txt"))); 470 base::FilePath::FromUTF8Unsafe("drive/root/Directory 1/Added file.txt")));
471 } 471 }
472 472
473 TEST_F(ChangeListProcessorTest, DeltaAddFileToNewButDeletedDirectory) { 473 TEST_F(ChangeListProcessorTest, DeltaAddFileToNewButDeletedDirectory) {
(...skipping 19 matching lines...) Expand all
493 directory.set_deleted(true); 493 directory.set_deleted(true);
494 change_lists[0]->mutable_entries()->push_back(directory); 494 change_lists[0]->mutable_entries()->push_back(directory);
495 change_lists[0]->mutable_parent_resource_ids()->push_back(kRootId); 495 change_lists[0]->mutable_parent_resource_ids()->push_back(kRootId);
496 496
497 change_lists[0]->set_largest_changestamp(16730); 497 change_lists[0]->set_largest_changestamp(16730);
498 498
499 // Apply the changelist and check the effect. 499 // Apply the changelist and check the effect.
500 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); 500 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList()));
501 FileChange changed_files; 501 FileChange changed_files;
502 EXPECT_EQ(FILE_ERROR_OK, 502 EXPECT_EQ(FILE_ERROR_OK,
503 ApplyChangeList(change_lists.Pass(), &changed_files)); 503 ApplyChangeList(std::move(change_lists), &changed_files));
504 504
505 int64_t changestamp = 0; 505 int64_t changestamp = 0;
506 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); 506 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp));
507 EXPECT_EQ(16730, changestamp); 507 EXPECT_EQ(16730, changestamp);
508 EXPECT_FALSE(GetResourceEntry("drive/root/New Directory/new_pdf_file.pdf")); 508 EXPECT_FALSE(GetResourceEntry("drive/root/New Directory/new_pdf_file.pdf"));
509 509
510 EXPECT_TRUE(changed_files.empty()); 510 EXPECT_TRUE(changed_files.empty());
511 } 511 }
512 512
513 TEST_F(ChangeListProcessorTest, RefreshDirectory) { 513 TEST_F(ChangeListProcessorTest, RefreshDirectory) {
(...skipping 17 matching lines...) Expand all
531 dir1.set_title(dir1.title() + " (renamed)"); 531 dir1.set_title(dir1.title() + " (renamed)");
532 change_list->mutable_entries()->push_back(dir1); 532 change_list->mutable_entries()->push_back(dir1);
533 change_list->mutable_parent_resource_ids()->push_back(kRootId); 533 change_list->mutable_parent_resource_ids()->push_back(kRootId);
534 534
535 // Update the directory with the map. 535 // Update the directory with the map.
536 ResourceEntry root; 536 ResourceEntry root;
537 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryByPath( 537 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryByPath(
538 util::GetDriveMyDriveRootPath(), &root)); 538 util::GetDriveMyDriveRootPath(), &root));
539 const int64_t kNewChangestamp = 12345; 539 const int64_t kNewChangestamp = 12345;
540 ResourceEntryVector refreshed_entries; 540 ResourceEntryVector refreshed_entries;
541 EXPECT_EQ(FILE_ERROR_OK, ChangeListProcessor::RefreshDirectory( 541 EXPECT_EQ(FILE_ERROR_OK,
542 metadata_.get(), 542 ChangeListProcessor::RefreshDirectory(
543 DirectoryFetchInfo(root.local_id(), kRootId, kNewChangestamp), 543 metadata_.get(),
544 change_list.Pass(), 544 DirectoryFetchInfo(root.local_id(), kRootId, kNewChangestamp),
545 &refreshed_entries)); 545 std::move(change_list), &refreshed_entries));
546 546
547 // "new_file" should be added. 547 // "new_file" should be added.
548 ResourceEntry entry; 548 ResourceEntry entry;
549 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryByPath( 549 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryByPath(
550 util::GetDriveMyDriveRootPath().AppendASCII(new_file.title()), &entry)); 550 util::GetDriveMyDriveRootPath().AppendASCII(new_file.title()), &entry));
551 551
552 // "Directory 1" should be renamed. 552 // "Directory 1" should be renamed.
553 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryByPath( 553 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryByPath(
554 util::GetDriveMyDriveRootPath().AppendASCII(dir1.title()), &entry)); 554 util::GetDriveMyDriveRootPath().AppendASCII(dir1.title()), &entry));
555 } 555 }
(...skipping 12 matching lines...) Expand all
568 "some-random-resource-id"); 568 "some-random-resource-id");
569 change_list->mutable_entries()->push_back(new_file); 569 change_list->mutable_entries()->push_back(new_file);
570 570
571 571
572 // Update the directory. 572 // Update the directory.
573 ResourceEntry root; 573 ResourceEntry root;
574 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryByPath( 574 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryByPath(
575 util::GetDriveMyDriveRootPath(), &root)); 575 util::GetDriveMyDriveRootPath(), &root));
576 const int64_t kNewChangestamp = 12345; 576 const int64_t kNewChangestamp = 12345;
577 ResourceEntryVector refreshed_entries; 577 ResourceEntryVector refreshed_entries;
578 EXPECT_EQ(FILE_ERROR_OK, ChangeListProcessor::RefreshDirectory( 578 EXPECT_EQ(FILE_ERROR_OK,
579 metadata_.get(), 579 ChangeListProcessor::RefreshDirectory(
580 DirectoryFetchInfo(root.local_id(), kRootId, kNewChangestamp), 580 metadata_.get(),
581 change_list.Pass(), 581 DirectoryFetchInfo(root.local_id(), kRootId, kNewChangestamp),
582 &refreshed_entries)); 582 std::move(change_list), &refreshed_entries));
583 583
584 // "new_file" should not be added. 584 // "new_file" should not be added.
585 ResourceEntry entry; 585 ResourceEntry entry;
586 EXPECT_EQ(FILE_ERROR_NOT_FOUND, metadata_->GetResourceEntryByPath( 586 EXPECT_EQ(FILE_ERROR_NOT_FOUND, metadata_->GetResourceEntryByPath(
587 util::GetDriveMyDriveRootPath().AppendASCII(new_file.title()), &entry)); 587 util::GetDriveMyDriveRootPath().AppendASCII(new_file.title()), &entry));
588 } 588 }
589 589
590 TEST_F(ChangeListProcessorTest, SharedFilesWithNoParentInFeed) { 590 TEST_F(ChangeListProcessorTest, SharedFilesWithNoParentInFeed) {
591 // Prepare metadata. 591 // Prepare metadata.
592 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); 592 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList()));
593 593
594 // Create change lists. 594 // Create change lists.
595 ScopedVector<ChangeList> change_lists; 595 ScopedVector<ChangeList> change_lists;
596 change_lists.push_back(new ChangeList); 596 change_lists.push_back(new ChangeList);
597 597
598 // Add a new file with non-existing parent resource id to the change lists. 598 // Add a new file with non-existing parent resource id to the change lists.
599 ResourceEntry new_file; 599 ResourceEntry new_file;
600 new_file.set_title("new_file"); 600 new_file.set_title("new_file");
601 new_file.set_resource_id("new_file_id"); 601 new_file.set_resource_id("new_file_id");
602 change_lists[0]->mutable_entries()->push_back(new_file); 602 change_lists[0]->mutable_entries()->push_back(new_file);
603 change_lists[0]->mutable_parent_resource_ids()->push_back("nonexisting"); 603 change_lists[0]->mutable_parent_resource_ids()->push_back("nonexisting");
604 change_lists[0]->set_largest_changestamp(kBaseResourceListChangestamp + 1); 604 change_lists[0]->set_largest_changestamp(kBaseResourceListChangestamp + 1);
605 605
606 FileChange changed_files; 606 FileChange changed_files;
607 EXPECT_EQ(FILE_ERROR_OK, 607 EXPECT_EQ(FILE_ERROR_OK,
608 ApplyChangeList(change_lists.Pass(), &changed_files)); 608 ApplyChangeList(std::move(change_lists), &changed_files));
609 609
610 // "new_file" should be added under drive/other. 610 // "new_file" should be added under drive/other.
611 ResourceEntry entry; 611 ResourceEntry entry;
612 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryByPath( 612 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryByPath(
613 util::GetDriveGrandRootPath().AppendASCII("other/new_file"), &entry)); 613 util::GetDriveGrandRootPath().AppendASCII("other/new_file"), &entry));
614 } 614 }
615 615
616 TEST_F(ChangeListProcessorTest, ModificationDate) { 616 TEST_F(ChangeListProcessorTest, ModificationDate) {
617 // Prepare metadata. 617 // Prepare metadata.
618 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); 618 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList()));
(...skipping 24 matching lines...) Expand all
643 new_file_local.set_title("new_file_local"); 643 new_file_local.set_title("new_file_local");
644 new_file_local.set_metadata_edit_state(ResourceEntry::DIRTY); 644 new_file_local.set_metadata_edit_state(ResourceEntry::DIRTY);
645 new_file_local.set_modification_date( 645 new_file_local.set_modification_date(
646 (now + base::TimeDelta::FromSeconds(1)).ToInternalValue()); 646 (now + base::TimeDelta::FromSeconds(1)).ToInternalValue());
647 std::string local_id; 647 std::string local_id;
648 EXPECT_EQ(FILE_ERROR_OK, metadata_->AddEntry(new_file_local, &local_id)); 648 EXPECT_EQ(FILE_ERROR_OK, metadata_->AddEntry(new_file_local, &local_id));
649 649
650 // Apply the change. 650 // Apply the change.
651 FileChange changed_files; 651 FileChange changed_files;
652 EXPECT_EQ(FILE_ERROR_OK, 652 EXPECT_EQ(FILE_ERROR_OK,
653 ApplyChangeList(change_lists.Pass(), &changed_files)); 653 ApplyChangeList(std::move(change_lists), &changed_files));
654 654
655 // The change is rejected due to the old modification date. 655 // The change is rejected due to the old modification date.
656 ResourceEntry entry; 656 ResourceEntry entry;
657 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryById(local_id, &entry)); 657 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryById(local_id, &entry));
658 EXPECT_EQ(new_file_local.title(), entry.title()); 658 EXPECT_EQ(new_file_local.title(), entry.title());
659 } 659 }
660 660
661 } // namespace internal 661 } // namespace internal
662 } // namespace drive 662 } // namespace drive
OLDNEW
« no previous file with comments | « components/drive/change_list_loader_unittest.cc ('k') | components/drive/directory_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698