Chromium Code Reviews| 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::GetTeamDrivesIntegrationSwitchName()); |
| 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 | |
| 674 std::vector<std::unique_ptr<ChangeList>> change_lists; | |
| 675 change_lists.push_back(base::MakeUnique<ChangeList>()); | |
| 676 change_lists[0]->mutable_team_drives()->push_back(team_drive); | |
| 677 change_lists[0]->set_largest_changestamp(kBaseResourceListChangestamp + 1); | |
| 678 | |
| 679 // Apply the changelist and check the effect. | |
| 680 EXPECT_EQ(FILE_ERROR_OK, ApplyFullResourceList(CreateBaseChangeList())); | |
| 681 | |
| 682 FileChange changed_files; | |
| 683 EXPECT_EQ(FILE_ERROR_OK, | |
| 684 ApplyChangeList(std::move(change_lists), &changed_files)); | |
| 685 | |
| 686 int64_t changestamp = 0; | |
| 687 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); | |
| 688 EXPECT_EQ(kBaseResourceListChangestamp + 1, changestamp); | |
| 689 | |
| 690 ResourceEntry entry; | |
| 691 EXPECT_EQ( | |
| 692 FILE_ERROR_OK, | |
| 693 metadata_->GetResourceEntryByPath( | |
| 694 util::GetDriveTeamDrivesRootPath().AppendASCII(kOldName), &entry)); | |
| 695 EXPECT_EQ(kTeamDriveId, entry.resource_id()); | |
| 696 | |
| 697 // Change to Team Drive entry is also conted as a file change. | |
| 698 EXPECT_EQ(1U, changed_files.size()); | |
| 699 | |
| 700 // Second change, which updates Team Drive name | |
| 701 change_lists.clear(); | |
| 702 change_lists.push_back(base::MakeUnique<ChangeList>()); | |
| 703 team_drive.set_title(kNewName); | |
| 704 change_lists[0]->mutable_team_drives()->push_back(team_drive); | |
| 705 change_lists[0]->set_largest_changestamp(kBaseResourceListChangestamp + 2); | |
| 706 EXPECT_EQ(FILE_ERROR_OK, | |
| 707 ApplyChangeList(std::move(change_lists), &changed_files)); | |
| 708 EXPECT_EQ( | |
| 709 FILE_ERROR_OK, | |
| 710 metadata_->GetResourceEntryByPath( | |
| 711 util::GetDriveTeamDrivesRootPath().AppendASCII(kNewName), &entry)); | |
| 712 EXPECT_EQ(kTeamDriveId, entry.resource_id()); | |
| 713 | |
| 714 // Delete the team drive | |
| 715 change_lists.clear(); | |
| 716 change_lists.push_back(base::MakeUnique<ChangeList>()); | |
| 717 change_lists[0]->set_largest_changestamp(kBaseResourceListChangestamp + 3); | |
|
hashimoto
2017/04/07 07:56:41
This is not a ChangeList which deletes something.
yamaguchi
2017/04/07 15:31:46
Done.
| |
| 718 EXPECT_EQ(FILE_ERROR_OK, | |
| 719 ApplyChangeList(std::move(change_lists), &changed_files)); | |
| 720 // TODO(yamaguchi): Verify the entry is deleted after implementing | |
| 721 // TD deletion. | |
| 722 // Currently this test just confirms it doesn't crash with such entry. | |
| 723 // EXPECT_EQ( | |
| 724 // FILE_ERROR_NOT_FOUND, | |
| 725 // metadata_->GetResourceEntryByPath( | |
| 726 // util::GetDriveTeamDrivesRootPath().AppendASCII(kNewName), | |
| 727 // &entry)); | |
| 728 } | |
| 729 | |
| 661 } // namespace internal | 730 } // namespace internal |
| 662 } // namespace drive | 731 } // namespace drive |
| OLD | NEW |