| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "google_apis/drive/gdata_errorcode.h" | 32 #include "google_apis/drive/gdata_errorcode.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 34 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" | 34 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" |
| 35 #include "third_party/leveldatabase/src/include/leveldb/env.h" | 35 #include "third_party/leveldatabase/src/include/leveldb/env.h" |
| 36 | 36 |
| 37 namespace sync_file_system { | 37 namespace sync_file_system { |
| 38 namespace drive_backend { | 38 namespace drive_backend { |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 fileapi::FileSystemURL URL(const GURL& origin, | 42 storage::FileSystemURL URL(const GURL& origin, const std::string& path) { |
| 43 const std::string& path) { | |
| 44 return CreateSyncableFileSystemURL( | 43 return CreateSyncableFileSystemURL( |
| 45 origin, base::FilePath::FromUTF8Unsafe(path)); | 44 origin, base::FilePath::FromUTF8Unsafe(path)); |
| 46 } | 45 } |
| 47 | 46 |
| 48 } // namespace | 47 } // namespace |
| 49 | 48 |
| 50 class ConflictResolverTest : public testing::Test { | 49 class ConflictResolverTest : public testing::Test { |
| 51 public: | 50 public: |
| 52 typedef FakeRemoteChangeProcessor::URLToFileChangesMap URLToFileChangesMap; | 51 typedef FakeRemoteChangeProcessor::URLToFileChangesMap URLToFileChangesMap; |
| 53 | 52 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 std::string CreateRemoteFile(const std::string& parent_folder_id, | 147 std::string CreateRemoteFile(const std::string& parent_folder_id, |
| 149 const std::string& title, | 148 const std::string& title, |
| 150 const std::string& content) { | 149 const std::string& content) { |
| 151 std::string file_id; | 150 std::string file_id; |
| 152 EXPECT_EQ(google_apis::HTTP_SUCCESS, | 151 EXPECT_EQ(google_apis::HTTP_SUCCESS, |
| 153 fake_drive_helper_->AddFile( | 152 fake_drive_helper_->AddFile( |
| 154 parent_folder_id, title, content, &file_id)); | 153 parent_folder_id, title, content, &file_id)); |
| 155 return file_id; | 154 return file_id; |
| 156 } | 155 } |
| 157 | 156 |
| 158 void CreateLocalFile(const fileapi::FileSystemURL& url) { | 157 void CreateLocalFile(const storage::FileSystemURL& url) { |
| 159 remote_change_processor_->UpdateLocalFileMetadata( | 158 remote_change_processor_->UpdateLocalFileMetadata( |
| 160 url, FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, | 159 url, FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, |
| 161 SYNC_FILE_TYPE_FILE)); | 160 SYNC_FILE_TYPE_FILE)); |
| 162 } | 161 } |
| 163 | 162 |
| 164 google_apis::GDataErrorCode AddFileToFolder( | 163 google_apis::GDataErrorCode AddFileToFolder( |
| 165 const std::string& parent_folder_id, | 164 const std::string& parent_folder_id, |
| 166 const std::string& file_id) { | 165 const std::string& file_id) { |
| 167 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 166 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
| 168 context_->GetDriveService()->AddResourceToDirectory( | 167 context_->GetDriveService()->AddResourceToDirectory( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 182 SyncStatusCode RunRemoteToLocalSyncer() { | 181 SyncStatusCode RunRemoteToLocalSyncer() { |
| 183 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 182 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
| 184 scoped_ptr<RemoteToLocalSyncer> syncer( | 183 scoped_ptr<RemoteToLocalSyncer> syncer( |
| 185 new RemoteToLocalSyncer(context_.get())); | 184 new RemoteToLocalSyncer(context_.get())); |
| 186 syncer->RunPreflight(SyncTaskToken::CreateForTesting( | 185 syncer->RunPreflight(SyncTaskToken::CreateForTesting( |
| 187 CreateResultReceiver(&status))); | 186 CreateResultReceiver(&status))); |
| 188 base::RunLoop().RunUntilIdle(); | 187 base::RunLoop().RunUntilIdle(); |
| 189 return status; | 188 return status; |
| 190 } | 189 } |
| 191 | 190 |
| 192 SyncStatusCode RunLocalToRemoteSyncer( | 191 SyncStatusCode RunLocalToRemoteSyncer(const storage::FileSystemURL& url, |
| 193 const fileapi::FileSystemURL& url, | 192 const FileChange& file_change) { |
| 194 const FileChange& file_change) { | |
| 195 SyncStatusCode status = SYNC_STATUS_UNKNOWN; | 193 SyncStatusCode status = SYNC_STATUS_UNKNOWN; |
| 196 base::FilePath local_path = base::FilePath(FILE_PATH_LITERAL("dummy")); | 194 base::FilePath local_path = base::FilePath(FILE_PATH_LITERAL("dummy")); |
| 197 if (file_change.IsAddOrUpdate()) | 195 if (file_change.IsAddOrUpdate()) |
| 198 CreateTemporaryFileInDir(database_dir_.path(), &local_path); | 196 CreateTemporaryFileInDir(database_dir_.path(), &local_path); |
| 199 scoped_ptr<LocalToRemoteSyncer> syncer(new LocalToRemoteSyncer( | 197 scoped_ptr<LocalToRemoteSyncer> syncer(new LocalToRemoteSyncer( |
| 200 context_.get(), | 198 context_.get(), |
| 201 SyncFileMetadata(file_change.file_type(), 0, base::Time()), | 199 SyncFileMetadata(file_change.file_type(), 0, base::Time()), |
| 202 file_change, local_path, url)); | 200 file_change, local_path, url)); |
| 203 syncer->RunPreflight(SyncTaskToken::CreateForTesting( | 201 syncer->RunPreflight(SyncTaskToken::CreateForTesting( |
| 204 CreateResultReceiver(&status))); | 202 CreateResultReceiver(&status))); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 | 375 |
| 378 TEST_F(ConflictResolverTest, ResolveConflict_RemoteFolderOnLocalFile) { | 376 TEST_F(ConflictResolverTest, ResolveConflict_RemoteFolderOnLocalFile) { |
| 379 const GURL kOrigin("chrome-extension://example"); | 377 const GURL kOrigin("chrome-extension://example"); |
| 380 const std::string sync_root = CreateSyncRoot(); | 378 const std::string sync_root = CreateSyncRoot(); |
| 381 const std::string app_root = CreateRemoteFolder(sync_root, kOrigin.host()); | 379 const std::string app_root = CreateRemoteFolder(sync_root, kOrigin.host()); |
| 382 InitializeMetadataDatabase(); | 380 InitializeMetadataDatabase(); |
| 383 RegisterApp(kOrigin.host(), app_root); | 381 RegisterApp(kOrigin.host(), app_root); |
| 384 RunRemoteToLocalSyncerUntilIdle(); | 382 RunRemoteToLocalSyncerUntilIdle(); |
| 385 | 383 |
| 386 const std::string kTitle = "foo"; | 384 const std::string kTitle = "foo"; |
| 387 fileapi::FileSystemURL kURL = URL(kOrigin, kTitle); | 385 storage::FileSystemURL kURL = URL(kOrigin, kTitle); |
| 388 | 386 |
| 389 // Create a file on local and sync it. | 387 // Create a file on local and sync it. |
| 390 CreateLocalFile(kURL); | 388 CreateLocalFile(kURL); |
| 391 RunLocalToRemoteSyncer( | 389 RunLocalToRemoteSyncer( |
| 392 kURL, | 390 kURL, |
| 393 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE)); | 391 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE)); |
| 394 | 392 |
| 395 // Create a folder on remote and sync it. | 393 // Create a folder on remote and sync it. |
| 396 const std::string primary = CreateRemoteFolder(app_root, kTitle); | 394 const std::string primary = CreateRemoteFolder(app_root, kTitle); |
| 397 EXPECT_EQ(SYNC_STATUS_OK, ListChanges()); | 395 EXPECT_EQ(SYNC_STATUS_OK, ListChanges()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 424 | 422 |
| 425 TEST_F(ConflictResolverTest, ResolveConflict_RemoteNestedFolderOnLocalFile) { | 423 TEST_F(ConflictResolverTest, ResolveConflict_RemoteNestedFolderOnLocalFile) { |
| 426 const GURL kOrigin("chrome-extension://example"); | 424 const GURL kOrigin("chrome-extension://example"); |
| 427 const std::string sync_root = CreateSyncRoot(); | 425 const std::string sync_root = CreateSyncRoot(); |
| 428 const std::string app_root = CreateRemoteFolder(sync_root, kOrigin.host()); | 426 const std::string app_root = CreateRemoteFolder(sync_root, kOrigin.host()); |
| 429 InitializeMetadataDatabase(); | 427 InitializeMetadataDatabase(); |
| 430 RegisterApp(kOrigin.host(), app_root); | 428 RegisterApp(kOrigin.host(), app_root); |
| 431 RunRemoteToLocalSyncerUntilIdle(); | 429 RunRemoteToLocalSyncerUntilIdle(); |
| 432 | 430 |
| 433 const std::string kTitle = "foo"; | 431 const std::string kTitle = "foo"; |
| 434 fileapi::FileSystemURL kURL = URL(kOrigin, kTitle); | 432 storage::FileSystemURL kURL = URL(kOrigin, kTitle); |
| 435 | 433 |
| 436 // Create a file on local and sync it. | 434 // Create a file on local and sync it. |
| 437 CreateLocalFile(kURL); | 435 CreateLocalFile(kURL); |
| 438 RunLocalToRemoteSyncer( | 436 RunLocalToRemoteSyncer( |
| 439 kURL, | 437 kURL, |
| 440 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE)); | 438 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE)); |
| 441 | 439 |
| 442 // Create a folder and subfolder in it on remote, and sync it. | 440 // Create a folder and subfolder in it on remote, and sync it. |
| 443 const std::string primary = CreateRemoteFolder(app_root, kTitle); | 441 const std::string primary = CreateRemoteFolder(app_root, kTitle); |
| 444 CreateRemoteFolder(primary, "nested"); | 442 CreateRemoteFolder(primary, "nested"); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 | 520 |
| 523 EXPECT_EQ(4, CountParents(file)); | 521 EXPECT_EQ(4, CountParents(file)); |
| 524 | 522 |
| 525 EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver()); | 523 EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver()); |
| 526 | 524 |
| 527 EXPECT_EQ(1, CountParents(file)); | 525 EXPECT_EQ(1, CountParents(file)); |
| 528 } | 526 } |
| 529 | 527 |
| 530 } // namespace drive_backend | 528 } // namespace drive_backend |
| 531 } // namespace sync_file_system | 529 } // namespace sync_file_system |
| OLD | NEW |