| OLD | NEW |
| 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/chromeos/change_list_processor.h" | 5 #include "components/drive/chromeos/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 #include <utility> |
| 10 | 10 |
| 11 #include "base/command_line.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "components/drive/chromeos/drive_test_util.h" | 17 #include "components/drive/chromeos/drive_test_util.h" |
| 17 #include "components/drive/chromeos/fake_free_disk_space_getter.h" | 18 #include "components/drive/chromeos/fake_free_disk_space_getter.h" |
| 18 #include "components/drive/chromeos/file_cache.h" | 19 #include "components/drive/chromeos/file_cache.h" |
| 19 #include "components/drive/chromeos/resource_metadata.h" | 20 #include "components/drive/chromeos/resource_metadata.h" |
| 20 #include "components/drive/drive.pb.h" | 21 #include "components/drive/drive.pb.h" |
| 21 #include "components/drive/file_change.h" | 22 #include "components/drive/file_change.h" |
| 22 #include "components/drive/file_system_core_util.h" | 23 #include "components/drive/file_system_core_util.h" |
| 23 #include "content/public/test/test_browser_thread_bundle.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
| 24 #include "google_apis/drive/drive_api_parser.h" | 25 #include "google_apis/drive/drive_api_parser.h" |
| 26 #include "google_apis/drive/drive_switches.h" |
| 25 #include "google_apis/drive/test_util.h" | 27 #include "google_apis/drive/test_util.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 29 |
| 28 namespace drive { | 30 namespace drive { |
| 29 namespace internal { | 31 namespace internal { |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| 32 | 34 |
| 33 const int64_t kBaseResourceListChangestamp = 123; | 35 const int64_t kBaseResourceListChangestamp = 123; |
| 34 const char kRootId[] = "fake_root"; | 36 const char kRootId[] = "fake_root"; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 metadata_storage_.reset(new ResourceMetadataStorage( | 112 metadata_storage_.reset(new ResourceMetadataStorage( |
| 111 temp_dir_.GetPath(), base::ThreadTaskRunnerHandle::Get().get())); | 113 temp_dir_.GetPath(), base::ThreadTaskRunnerHandle::Get().get())); |
| 112 ASSERT_TRUE(metadata_storage_->Initialize()); | 114 ASSERT_TRUE(metadata_storage_->Initialize()); |
| 113 | 115 |
| 114 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter); | 116 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter); |
| 115 cache_.reset(new FileCache(metadata_storage_.get(), temp_dir_.GetPath(), | 117 cache_.reset(new FileCache(metadata_storage_.get(), temp_dir_.GetPath(), |
| 116 base::ThreadTaskRunnerHandle::Get().get(), | 118 base::ThreadTaskRunnerHandle::Get().get(), |
| 117 fake_free_disk_space_getter_.get())); | 119 fake_free_disk_space_getter_.get())); |
| 118 ASSERT_TRUE(cache_->Initialize()); | 120 ASSERT_TRUE(cache_->Initialize()); |
| 119 | 121 |
| 120 metadata_.reset(new internal::ResourceMetadata( | 122 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 121 metadata_storage_.get(), cache_.get(), | 123 google_apis::kEnableTeamDrives); |
| 122 base::ThreadTaskRunnerHandle::Get())); | 124 metadata_.reset( |
| 125 new internal::ResourceMetadata(metadata_storage_.get(), cache_.get(), |
| 126 base::ThreadTaskRunnerHandle::Get())); |
| 123 ASSERT_EQ(FILE_ERROR_OK, metadata_->Initialize()); | 127 ASSERT_EQ(FILE_ERROR_OK, metadata_->Initialize()); |
| 124 } | 128 } |
| 125 | 129 |
| 126 // Applies the |changes| to |metadata_| as a full resource list of changestamp | 130 // Applies the |changes| to |metadata_| as a full resource list of changestamp |
| 127 // |kBaseResourceListChangestamp|. | 131 // |kBaseResourceListChangestamp|. |
| 128 FileError ApplyFullResourceList( | 132 FileError ApplyFullResourceList( |
| 129 std::vector<std::unique_ptr<ChangeList>> changes) { | 133 std::vector<std::unique_ptr<ChangeList>> changes) { |
| 130 std::unique_ptr<google_apis::AboutResource> about_resource( | 134 std::unique_ptr<google_apis::AboutResource> about_resource( |
| 131 new google_apis::AboutResource); | 135 new google_apis::AboutResource); |
| 132 about_resource->set_largest_change_id(kBaseResourceListChangestamp); | 136 about_resource->set_largest_change_id(kBaseResourceListChangestamp); |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 FileChange changed_files; | 655 FileChange changed_files; |
| 652 EXPECT_EQ(FILE_ERROR_OK, | 656 EXPECT_EQ(FILE_ERROR_OK, |
| 653 ApplyChangeList(std::move(change_lists), &changed_files)); | 657 ApplyChangeList(std::move(change_lists), &changed_files)); |
| 654 | 658 |
| 655 // The change is rejected due to the old modification date. | 659 // The change is rejected due to the old modification date. |
| 656 ResourceEntry entry; | 660 ResourceEntry entry; |
| 657 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryById(local_id, &entry)); | 661 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetResourceEntryById(local_id, &entry)); |
| 658 EXPECT_EQ(new_file_local.title(), entry.title()); | 662 EXPECT_EQ(new_file_local.title(), entry.title()); |
| 659 } | 663 } |
| 660 | 664 |
| 665 TEST_F(ChangeListProcessorTest, DeltaTeamDriveChange) { |
| 666 const char kTeamDriveId[] = "ID_OF_TEAM_DRIVE"; |
| 667 const char kOldName[] = "Old Name"; |
| 668 const char kNewName[] = "New Name"; |
| 669 |
| 670 ResourceEntry team_drive; |
| 671 team_drive.set_title(kOldName); |
| 672 team_drive.set_resource_id(kTeamDriveId); |
| 673 team_drive.set_parent_local_id(util::kDriveTeamDrivesDirLocalId); |
| 674 |
| 675 std::vector<std::unique_ptr<ChangeList>> change_lists; |
| 676 change_lists.push_back(base::MakeUnique<ChangeList>()); |
| 677 change_lists[0]->mutable_entries()->push_back(team_drive); |
| 678 change_lists[0]->set_largest_changestamp(kBaseResourceListChangestamp + 1); |
| 679 change_lists[0]->mutable_parent_resource_ids()->push_back(""); |
| 680 |
| 681 // Apply the changelist and check the effect. |
| 682 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); |
| 683 |
| 684 FileChange changed_files; |
| 685 EXPECT_EQ(FILE_ERROR_OK, |
| 686 ApplyChangeList(std::move(change_lists), &changed_files)); |
| 687 |
| 688 int64_t changestamp = 0; |
| 689 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); |
| 690 EXPECT_EQ(kBaseResourceListChangestamp + 1, changestamp); |
| 691 |
| 692 ResourceEntry entry; |
| 693 EXPECT_EQ( |
| 694 FILE_ERROR_OK, |
| 695 metadata_->GetResourceEntryByPath( |
| 696 util::GetDriveTeamDrivesRootPath().AppendASCII(kOldName), &entry)); |
| 697 EXPECT_EQ(kTeamDriveId, entry.resource_id()); |
| 698 |
| 699 // Change to Team Drive entry is also conted as a file change. |
| 700 EXPECT_EQ(1U, changed_files.size()); |
| 701 |
| 702 // Second change, which updates Team Drive name |
| 703 change_lists.clear(); |
| 704 change_lists.push_back(base::MakeUnique<ChangeList>()); |
| 705 team_drive.set_title(kNewName); |
| 706 change_lists[0]->mutable_entries()->push_back(team_drive); |
| 707 change_lists[0]->set_largest_changestamp(kBaseResourceListChangestamp + 2); |
| 708 change_lists[0]->mutable_parent_resource_ids()->push_back(""); |
| 709 EXPECT_EQ(FILE_ERROR_OK, |
| 710 ApplyChangeList(std::move(change_lists), &changed_files)); |
| 711 EXPECT_EQ( |
| 712 FILE_ERROR_OK, |
| 713 metadata_->GetResourceEntryByPath( |
| 714 util::GetDriveTeamDrivesRootPath().AppendASCII(kNewName), &entry)); |
| 715 EXPECT_EQ(kTeamDriveId, entry.resource_id()); |
| 716 |
| 717 // Delete the team drive. |
| 718 change_lists.clear(); |
| 719 change_lists.push_back(base::MakeUnique<ChangeList>()); |
| 720 change_lists[0]->set_largest_changestamp(kBaseResourceListChangestamp + 3); |
| 721 team_drive.set_deleted(true); |
| 722 change_lists[0]->mutable_parent_resource_ids()->push_back(""); |
| 723 change_lists[0]->mutable_entries()->push_back(team_drive); |
| 724 EXPECT_EQ(FILE_ERROR_OK, |
| 725 ApplyChangeList(std::move(change_lists), &changed_files)); |
| 726 EXPECT_EQ( |
| 727 FILE_ERROR_NOT_FOUND, |
| 728 metadata_->GetResourceEntryByPath( |
| 729 util::GetDriveTeamDrivesRootPath().AppendASCII(kNewName), &entry)); |
| 730 } |
| 731 |
| 661 } // namespace internal | 732 } // namespace internal |
| 662 } // namespace drive | 733 } // namespace drive |
| OLD | NEW |