| 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/sync_file_system/drive_backend/conflict_resolver.h" | 5 #include "chrome/browser/sync_file_system/drive_backend/conflict_resolver.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 typedef FakeRemoteChangeProcessor::URLToFileChangesMap URLToFileChangesMap; | 54 typedef FakeRemoteChangeProcessor::URLToFileChangesMap URLToFileChangesMap; |
| 55 | 55 |
| 56 ConflictResolverTest() | 56 ConflictResolverTest() |
| 57 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} | 57 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} |
| 58 ~ConflictResolverTest() override {} | 58 ~ConflictResolverTest() override {} |
| 59 | 59 |
| 60 void SetUp() override { | 60 void SetUp() override { |
| 61 ASSERT_TRUE(database_dir_.CreateUniqueTempDir()); | 61 ASSERT_TRUE(database_dir_.CreateUniqueTempDir()); |
| 62 in_memory_env_.reset(leveldb::NewMemEnv(leveldb::Env::Default())); | 62 in_memory_env_.reset(leveldb::NewMemEnv(leveldb::Env::Default())); |
| 63 | 63 |
| 64 scoped_ptr<FakeDriveServiceWrapper> | 64 std::unique_ptr<FakeDriveServiceWrapper> fake_drive_service( |
| 65 fake_drive_service(new FakeDriveServiceWrapper); | 65 new FakeDriveServiceWrapper); |
| 66 scoped_ptr<drive::DriveUploaderInterface> | 66 std::unique_ptr<drive::DriveUploaderInterface> drive_uploader( |
| 67 drive_uploader(new FakeDriveUploader(fake_drive_service.get())); | 67 new FakeDriveUploader(fake_drive_service.get())); |
| 68 fake_drive_helper_.reset( | 68 fake_drive_helper_.reset( |
| 69 new FakeDriveServiceHelper(fake_drive_service.get(), | 69 new FakeDriveServiceHelper(fake_drive_service.get(), |
| 70 drive_uploader.get(), | 70 drive_uploader.get(), |
| 71 kSyncRootFolderTitle)); | 71 kSyncRootFolderTitle)); |
| 72 remote_change_processor_.reset(new FakeRemoteChangeProcessor); | 72 remote_change_processor_.reset(new FakeRemoteChangeProcessor); |
| 73 | 73 |
| 74 context_.reset(new SyncEngineContext( | 74 context_.reset(new SyncEngineContext( |
| 75 std::move(fake_drive_service), std::move(drive_uploader), | 75 std::move(fake_drive_service), std::move(drive_uploader), |
| 76 nullptr /* task_logger */, base::ThreadTaskRunnerHandle::Get(), | 76 nullptr /* task_logger */, base::ThreadTaskRunnerHandle::Get(), |
| 77 base::ThreadTaskRunnerHandle::Get(), nullptr /* worker_pool */)); | 77 base::ThreadTaskRunnerHandle::Get(), nullptr /* worker_pool */)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 95 base::RunLoop().RunUntilIdle(); | 95 base::RunLoop().RunUntilIdle(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 void InitializeMetadataDatabase() { | 98 void InitializeMetadataDatabase() { |
| 99 SyncEngineInitializer* initializer = | 99 SyncEngineInitializer* initializer = |
| 100 new SyncEngineInitializer(context_.get(), | 100 new SyncEngineInitializer(context_.get(), |
| 101 database_dir_.path(), | 101 database_dir_.path(), |
| 102 in_memory_env_.get()); | 102 in_memory_env_.get()); |
| 103 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 103 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
| 104 sync_task_manager_->ScheduleSyncTask( | 104 sync_task_manager_->ScheduleSyncTask( |
| 105 FROM_HERE, | 105 FROM_HERE, std::unique_ptr<SyncTask>(initializer), |
| 106 scoped_ptr<SyncTask>(initializer), | |
| 107 SyncTaskManager::PRIORITY_MED, | 106 SyncTaskManager::PRIORITY_MED, |
| 108 base::Bind(&ConflictResolverTest::DidInitializeMetadataDatabase, | 107 base::Bind(&ConflictResolverTest::DidInitializeMetadataDatabase, |
| 109 base::Unretained(this), initializer, &status)); | 108 base::Unretained(this), initializer, &status)); |
| 110 | 109 |
| 111 base::RunLoop().RunUntilIdle(); | 110 base::RunLoop().RunUntilIdle(); |
| 112 EXPECT_EQ(SYNC_STATUS_OK, status); | 111 EXPECT_EQ(SYNC_STATUS_OK, status); |
| 113 } | 112 } |
| 114 | 113 |
| 115 void DidInitializeMetadataDatabase(SyncEngineInitializer* initializer, | 114 void DidInitializeMetadataDatabase(SyncEngineInitializer* initializer, |
| 116 SyncStatusCode* status_out, | 115 SyncStatusCode* status_out, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 const std::string& file_id) { | 164 const std::string& file_id) { |
| 166 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; | 165 google_apis::DriveApiErrorCode error = google_apis::DRIVE_OTHER_ERROR; |
| 167 context_->GetDriveService()->AddResourceToDirectory( | 166 context_->GetDriveService()->AddResourceToDirectory( |
| 168 parent_folder_id, file_id, | 167 parent_folder_id, file_id, |
| 169 CreateResultReceiver(&error)); | 168 CreateResultReceiver(&error)); |
| 170 base::RunLoop().RunUntilIdle(); | 169 base::RunLoop().RunUntilIdle(); |
| 171 return error; | 170 return error; |
| 172 } | 171 } |
| 173 | 172 |
| 174 int CountParents(const std::string& file_id) { | 173 int CountParents(const std::string& file_id) { |
| 175 scoped_ptr<google_apis::FileResource> entry; | 174 std::unique_ptr<google_apis::FileResource> entry; |
| 176 EXPECT_EQ(google_apis::HTTP_SUCCESS, | 175 EXPECT_EQ(google_apis::HTTP_SUCCESS, |
| 177 fake_drive_helper_->GetFileResource(file_id, &entry)); | 176 fake_drive_helper_->GetFileResource(file_id, &entry)); |
| 178 return entry->parents().size(); | 177 return entry->parents().size(); |
| 179 } | 178 } |
| 180 | 179 |
| 181 SyncStatusCode RunRemoteToLocalSyncer() { | 180 SyncStatusCode RunRemoteToLocalSyncer() { |
| 182 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 181 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
| 183 scoped_ptr<RemoteToLocalSyncer> syncer( | 182 std::unique_ptr<RemoteToLocalSyncer> syncer( |
| 184 new RemoteToLocalSyncer(context_.get())); | 183 new RemoteToLocalSyncer(context_.get())); |
| 185 syncer->RunPreflight(SyncTaskToken::CreateForTesting( | 184 syncer->RunPreflight(SyncTaskToken::CreateForTesting( |
| 186 CreateResultReceiver(&status))); | 185 CreateResultReceiver(&status))); |
| 187 base::RunLoop().RunUntilIdle(); | 186 base::RunLoop().RunUntilIdle(); |
| 188 return status; | 187 return status; |
| 189 } | 188 } |
| 190 | 189 |
| 191 SyncStatusCode RunLocalToRemoteSyncer(const storage::FileSystemURL& url, | 190 SyncStatusCode RunLocalToRemoteSyncer(const storage::FileSystemURL& url, |
| 192 const FileChange& file_change) { | 191 const FileChange& file_change) { |
| 193 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 192 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
| 194 base::FilePath local_path = base::FilePath(FILE_PATH_LITERAL("dummy")); | 193 base::FilePath local_path = base::FilePath(FILE_PATH_LITERAL("dummy")); |
| 195 if (file_change.IsAddOrUpdate()) | 194 if (file_change.IsAddOrUpdate()) |
| 196 CreateTemporaryFileInDir(database_dir_.path(), &local_path); | 195 CreateTemporaryFileInDir(database_dir_.path(), &local_path); |
| 197 scoped_ptr<LocalToRemoteSyncer> syncer(new LocalToRemoteSyncer( | 196 std::unique_ptr<LocalToRemoteSyncer> syncer(new LocalToRemoteSyncer( |
| 198 context_.get(), | 197 context_.get(), |
| 199 SyncFileMetadata(file_change.file_type(), 0, base::Time()), | 198 SyncFileMetadata(file_change.file_type(), 0, base::Time()), file_change, |
| 200 file_change, local_path, url)); | 199 local_path, url)); |
| 201 syncer->RunPreflight(SyncTaskToken::CreateForTesting( | 200 syncer->RunPreflight(SyncTaskToken::CreateForTesting( |
| 202 CreateResultReceiver(&status))); | 201 CreateResultReceiver(&status))); |
| 203 base::RunLoop().RunUntilIdle(); | 202 base::RunLoop().RunUntilIdle(); |
| 204 if (status == SYNC_STATUS_OK) | 203 if (status == SYNC_STATUS_OK) |
| 205 remote_change_processor_->ClearLocalChanges(url); | 204 remote_change_processor_->ClearLocalChanges(url); |
| 206 return status; | 205 return status; |
| 207 } | 206 } |
| 208 | 207 |
| 209 void RunRemoteToLocalSyncerUntilIdle() { | 208 void RunRemoteToLocalSyncerUntilIdle() { |
| 210 const int kRetryLimit = 100; | 209 const int kRetryLimit = 100; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 227 resolver.RunPreflight(SyncTaskToken::CreateForTesting( | 226 resolver.RunPreflight(SyncTaskToken::CreateForTesting( |
| 228 CreateResultReceiver(&status))); | 227 CreateResultReceiver(&status))); |
| 229 base::RunLoop().RunUntilIdle(); | 228 base::RunLoop().RunUntilIdle(); |
| 230 return status; | 229 return status; |
| 231 } | 230 } |
| 232 | 231 |
| 233 SyncStatusCode ListChanges() { | 232 SyncStatusCode ListChanges() { |
| 234 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 233 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
| 235 sync_task_manager_->ScheduleSyncTask( | 234 sync_task_manager_->ScheduleSyncTask( |
| 236 FROM_HERE, | 235 FROM_HERE, |
| 237 scoped_ptr<SyncTask>(new ListChangesTask(context_.get())), | 236 std::unique_ptr<SyncTask>(new ListChangesTask(context_.get())), |
| 238 SyncTaskManager::PRIORITY_MED, | 237 SyncTaskManager::PRIORITY_MED, CreateResultReceiver(&status)); |
| 239 CreateResultReceiver(&status)); | |
| 240 base::RunLoop().RunUntilIdle(); | 238 base::RunLoop().RunUntilIdle(); |
| 241 return status; | 239 return status; |
| 242 } | 240 } |
| 243 | 241 |
| 244 ScopedVector<google_apis::FileResource> | 242 ScopedVector<google_apis::FileResource> |
| 245 GetResourceEntriesForParentAndTitle(const std::string& parent_folder_id, | 243 GetResourceEntriesForParentAndTitle(const std::string& parent_folder_id, |
| 246 const std::string& title) { | 244 const std::string& title) { |
| 247 ScopedVector<google_apis::FileResource> entries; | 245 ScopedVector<google_apis::FileResource> entries; |
| 248 EXPECT_EQ(google_apis::HTTP_SUCCESS, | 246 EXPECT_EQ(google_apis::HTTP_SUCCESS, |
| 249 fake_drive_helper_->SearchByTitle( | 247 fake_drive_helper_->SearchByTitle( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 266 } | 264 } |
| 267 | 265 |
| 268 void VerifyLocalChangeConsistency( | 266 void VerifyLocalChangeConsistency( |
| 269 const URLToFileChangesMap& expected_changes) { | 267 const URLToFileChangesMap& expected_changes) { |
| 270 remote_change_processor_->VerifyConsistency(expected_changes); | 268 remote_change_processor_->VerifyConsistency(expected_changes); |
| 271 } | 269 } |
| 272 | 270 |
| 273 private: | 271 private: |
| 274 content::TestBrowserThreadBundle thread_bundle_; | 272 content::TestBrowserThreadBundle thread_bundle_; |
| 275 base::ScopedTempDir database_dir_; | 273 base::ScopedTempDir database_dir_; |
| 276 scoped_ptr<leveldb::Env> in_memory_env_; | 274 std::unique_ptr<leveldb::Env> in_memory_env_; |
| 277 | 275 |
| 278 scoped_ptr<SyncEngineContext> context_; | 276 std::unique_ptr<SyncEngineContext> context_; |
| 279 scoped_ptr<FakeDriveServiceHelper> fake_drive_helper_; | 277 std::unique_ptr<FakeDriveServiceHelper> fake_drive_helper_; |
| 280 scoped_ptr<FakeRemoteChangeProcessor> remote_change_processor_; | 278 std::unique_ptr<FakeRemoteChangeProcessor> remote_change_processor_; |
| 281 | 279 |
| 282 scoped_ptr<SyncTaskManager> sync_task_manager_; | 280 std::unique_ptr<SyncTaskManager> sync_task_manager_; |
| 283 | 281 |
| 284 DISALLOW_COPY_AND_ASSIGN(ConflictResolverTest); | 282 DISALLOW_COPY_AND_ASSIGN(ConflictResolverTest); |
| 285 }; | 283 }; |
| 286 | 284 |
| 287 TEST_F(ConflictResolverTest, NoFileToBeResolved) { | 285 TEST_F(ConflictResolverTest, NoFileToBeResolved) { |
| 288 const GURL kOrigin("chrome-extension://example"); | 286 const GURL kOrigin("chrome-extension://example"); |
| 289 const std::string sync_root = CreateSyncRoot(); | 287 const std::string sync_root = CreateSyncRoot(); |
| 290 const std::string app_root = CreateRemoteFolder(sync_root, kOrigin.host()); | 288 const std::string app_root = CreateRemoteFolder(sync_root, kOrigin.host()); |
| 291 InitializeMetadataDatabase(); | 289 InitializeMetadataDatabase(); |
| 292 RegisterApp(kOrigin.host(), app_root); | 290 RegisterApp(kOrigin.host(), app_root); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 | 518 |
| 521 EXPECT_EQ(4, CountParents(file)); | 519 EXPECT_EQ(4, CountParents(file)); |
| 522 | 520 |
| 523 EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver()); | 521 EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver()); |
| 524 | 522 |
| 525 EXPECT_EQ(1, CountParents(file)); | 523 EXPECT_EQ(1, CountParents(file)); |
| 526 } | 524 } |
| 527 | 525 |
| 528 } // namespace drive_backend | 526 } // namespace drive_backend |
| 529 } // namespace sync_file_system | 527 } // namespace sync_file_system |
| OLD | NEW |