drive_backend_sync_unittest.cc revision 46d4c2bc3267f3f028f39e7e311b0f89aba2e4fd
1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include <algorithm> 6#include <stack> 7 8#include "base/file_util.h" 9#include "base/message_loop/message_loop.h" 10#include "base/run_loop.h" 11#include "chrome/browser/drive/drive_uploader.h" 12#include "chrome/browser/drive/fake_drive_service.h" 13#include "chrome/browser/drive/test_util.h" 14#include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants.h" 15#include "chrome/browser/sync_file_system/drive_backend/fake_drive_service_helper.h" 16#include "chrome/browser/sync_file_system/drive_backend/metadata_database.h" 17#include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h" 18#include "chrome/browser/sync_file_system/drive_backend/sync_engine.h" 19#include "chrome/browser/sync_file_system/drive_backend/sync_worker.h" 20#include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h" 21#include "chrome/browser/sync_file_system/local/local_file_sync_context.h" 22#include "chrome/browser/sync_file_system/local/local_file_sync_service.h" 23#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" 24#include "chrome/browser/sync_file_system/sync_file_system_test_util.h" 25#include "chrome/browser/sync_file_system/syncable_file_system_util.h" 26#include "chrome/test/base/testing_profile.h" 27#include "content/public/test/test_browser_thread.h" 28#include "content/public/test/test_browser_thread_bundle.h" 29#include "extensions/common/extension.h" 30#include "google_apis/drive/drive_api_parser.h" 31#include "testing/gtest/include/gtest/gtest.h" 32#include "third_party/leveldatabase/src/helpers/memenv/memenv.h" 33#include "third_party/leveldatabase/src/include/leveldb/env.h" 34#include "webkit/browser/fileapi/file_system_context.h" 35 36#define FPL(a) FILE_PATH_LITERAL(a) 37 38namespace sync_file_system { 39namespace drive_backend { 40 41typedef fileapi::FileSystemOperation::FileEntryList FileEntryList; 42 43namespace { 44 45template <typename T> 46void SetValueAndCallClosure(const base::Closure& closure, 47 T* arg_out, 48 T arg) { 49 *arg_out = base::internal::CallbackForward(arg); 50 closure.Run(); 51} 52 53void SetSyncStatusAndUrl(const base::Closure& closure, 54 SyncStatusCode* status_out, 55 fileapi::FileSystemURL* url_out, 56 SyncStatusCode status, 57 const fileapi::FileSystemURL& url) { 58 *status_out = status; 59 *url_out = url; 60 closure.Run(); 61} 62 63} // namespace 64 65class DriveBackendSyncTest : public testing::Test, 66 public LocalFileSyncService::Observer, 67 public RemoteFileSyncService::Observer { 68 public: 69 DriveBackendSyncTest() 70 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 71 pending_remote_changes_(0), 72 pending_local_changes_(0) {} 73 virtual ~DriveBackendSyncTest() {} 74 75 virtual void SetUp() OVERRIDE { 76 ASSERT_TRUE(base_dir_.CreateUniqueTempDir()); 77 in_memory_env_.reset(leveldb::NewMemEnv(leveldb::Env::Default())); 78 79 io_task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread( 80 content::BrowserThread::IO); 81 scoped_refptr<base::SequencedWorkerPool> worker_pool( 82 content::BrowserThread::GetBlockingPool()); 83 worker_task_runner_ = 84 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( 85 worker_pool->GetSequenceToken(), 86 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 87 file_task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread( 88 content::BrowserThread::FILE); 89 90 RegisterSyncableFileSystem(); 91 local_sync_service_ = LocalFileSyncService::CreateForTesting( 92 &profile_, in_memory_env_.get()); 93 local_sync_service_->AddChangeObserver(this); 94 95 scoped_ptr<drive::FakeDriveService> 96 drive_service(new drive::FakeDriveService); 97 drive_service->Initialize("test@example.com"); 98 ASSERT_TRUE(drive::test_util::SetUpTestEntries(drive_service.get())); 99 100 scoped_ptr<drive::DriveUploaderInterface> uploader( 101 new drive::DriveUploader(drive_service.get(), 102 file_task_runner_.get())); 103 104 fake_drive_service_helper_.reset(new FakeDriveServiceHelper( 105 drive_service.get(), uploader.get(), 106 kSyncRootFolderTitle)); 107 108 remote_sync_service_.reset(new SyncEngine( 109 drive_service.PassAs<drive::DriveServiceInterface>(), 110 uploader.Pass(), 111 file_task_runner_.get(), 112 NULL, NULL, NULL)); 113 remote_sync_service_->AddServiceObserver(this); 114 remote_sync_service_->Initialize(base_dir_.path(), 115 NULL, 116 worker_task_runner_.get(), 117 in_memory_env_.get()); 118 remote_sync_service_->SetSyncEnabled(true); 119 120 local_sync_service_->SetLocalChangeProcessor(remote_sync_service_.get()); 121 remote_sync_service_->SetRemoteChangeProcessor(local_sync_service_.get()); 122 } 123 124 virtual void TearDown() OVERRIDE { 125 typedef std::map<std::string, CannedSyncableFileSystem*>::iterator iterator; 126 for (iterator itr = file_systems_.begin(); 127 itr != file_systems_.end(); ++itr) { 128 itr->second->TearDown(); 129 delete itr->second; 130 } 131 file_systems_.clear(); 132 133 local_sync_service_->Shutdown(); 134 135 fake_drive_service_helper_.reset(); 136 local_sync_service_.reset(); 137 remote_sync_service_.reset(); 138 139 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 140 base::RunLoop().RunUntilIdle(); 141 RevokeSyncableFileSystem(); 142 } 143 144 virtual void OnRemoteChangeQueueUpdated(int64 pending_changes_hint) OVERRIDE { 145 pending_remote_changes_ = pending_changes_hint; 146 } 147 148 virtual void OnLocalChangeAvailable(int64 pending_changes_hint) OVERRIDE { 149 pending_local_changes_ = pending_changes_hint; 150 } 151 152 protected: 153 fileapi::FileSystemURL CreateURL(const std::string& app_id, 154 const base::FilePath::StringType& path) { 155 return CreateURL(app_id, base::FilePath(path)); 156 } 157 158 fileapi::FileSystemURL CreateURL(const std::string& app_id, 159 const base::FilePath& path) { 160 GURL origin = extensions::Extension::GetBaseURLFromExtensionId(app_id); 161 return CreateSyncableFileSystemURL(origin, path); 162 } 163 164 bool GetAppRootFolderID(const std::string& app_id, 165 std::string* folder_id) { 166 base::RunLoop run_loop; 167 bool success = false; 168 FileTracker tracker; 169 PostTaskAndReplyWithResult( 170 worker_task_runner_, 171 FROM_HERE, 172 base::Bind(&MetadataDatabase::FindAppRootTracker, 173 base::Unretained(metadata_database()), 174 app_id, 175 &tracker), 176 base::Bind(&SetValueAndCallClosure<bool>, 177 run_loop.QuitClosure(), 178 &success)); 179 run_loop.Run(); 180 if (!success) 181 return false; 182 *folder_id = tracker.file_id(); 183 return true; 184 } 185 186 std::string GetFileIDByPath(const std::string& app_id, 187 const base::FilePath::StringType& path) { 188 return GetFileIDByPath(app_id, base::FilePath(path)); 189 } 190 191 std::string GetFileIDByPath(const std::string& app_id, 192 const base::FilePath& path) { 193 base::RunLoop run_loop; 194 bool success = false; 195 FileTracker tracker; 196 base::FilePath result_path; 197 base::FilePath normalized_path = path.NormalizePathSeparators(); 198 PostTaskAndReplyWithResult( 199 worker_task_runner_, 200 FROM_HERE, 201 base::Bind(&MetadataDatabase::FindNearestActiveAncestor, 202 base::Unretained(metadata_database()), 203 app_id, 204 normalized_path, 205 &tracker, 206 &result_path), 207 base::Bind(&SetValueAndCallClosure<bool>, 208 run_loop.QuitClosure(), 209 &success)); 210 run_loop.Run(); 211 EXPECT_TRUE(success); 212 EXPECT_EQ(normalized_path, result_path); 213 return tracker.file_id(); 214 } 215 216 SyncStatusCode RegisterApp(const std::string& app_id) { 217 GURL origin = extensions::Extension::GetBaseURLFromExtensionId(app_id); 218 if (!ContainsKey(file_systems_, app_id)) { 219 CannedSyncableFileSystem* file_system = new CannedSyncableFileSystem( 220 origin, in_memory_env_.get(), 221 io_task_runner_.get(), file_task_runner_.get()); 222 file_system->SetUp(CannedSyncableFileSystem::QUOTA_DISABLED); 223 224 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 225 base::RunLoop run_loop; 226 local_sync_service_->MaybeInitializeFileSystemContext( 227 origin, file_system->file_system_context(), 228 base::Bind(&SetValueAndCallClosure<SyncStatusCode>, 229 run_loop.QuitClosure(), &status)); 230 run_loop.Run(); 231 EXPECT_EQ(SYNC_STATUS_OK, status); 232 233 file_system->backend()->sync_context()-> 234 set_mock_notify_changes_duration_in_sec(0); 235 236 EXPECT_EQ(base::File::FILE_OK, file_system->OpenFileSystem()); 237 file_systems_[app_id] = file_system; 238 } 239 240 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 241 base::RunLoop run_loop; 242 remote_sync_service_->RegisterOrigin( 243 origin, 244 base::Bind(&SetValueAndCallClosure<SyncStatusCode>, 245 run_loop.QuitClosure(), &status)); 246 run_loop.Run(); 247 return status; 248 } 249 250 void AddLocalFolder(const std::string& app_id, 251 const base::FilePath::StringType& path) { 252 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); 253 EXPECT_EQ(base::File::FILE_OK, 254 file_systems_[app_id]->CreateDirectory( 255 CreateURL(app_id, path))); 256 } 257 258 void AddOrUpdateLocalFile(const std::string& app_id, 259 const base::FilePath::StringType& path, 260 const std::string& content) { 261 fileapi::FileSystemURL url(CreateURL(app_id, path)); 262 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); 263 EXPECT_EQ(base::File::FILE_OK, file_systems_[app_id]->CreateFile(url)); 264 int64 bytes_written = file_systems_[app_id]->WriteString(url, content); 265 EXPECT_EQ(static_cast<int64>(content.size()), bytes_written); 266 base::RunLoop().RunUntilIdle(); 267 } 268 269 void UpdateLocalFile(const std::string& app_id, 270 const base::FilePath::StringType& path, 271 const std::string& content) { 272 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); 273 int64 bytes_written = file_systems_[app_id]->WriteString( 274 CreateURL(app_id, path), content); 275 EXPECT_EQ(static_cast<int64>(content.size()), bytes_written); 276 base::RunLoop().RunUntilIdle(); 277 } 278 279 void RemoveLocal(const std::string& app_id, 280 const base::FilePath::StringType& path) { 281 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); 282 EXPECT_EQ(base::File::FILE_OK, 283 file_systems_[app_id]->Remove( 284 CreateURL(app_id, path), 285 true /* recursive */)); 286 base::RunLoop().RunUntilIdle(); 287 } 288 289 SyncStatusCode ProcessLocalChange() { 290 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 291 fileapi::FileSystemURL url; 292 base::RunLoop run_loop; 293 local_sync_service_->ProcessLocalChange(base::Bind( 294 &SetSyncStatusAndUrl, run_loop.QuitClosure(), &status, &url)); 295 run_loop.Run(); 296 return status; 297 } 298 299 SyncStatusCode ProcessRemoteChange() { 300 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 301 fileapi::FileSystemURL url; 302 base::RunLoop run_loop; 303 remote_sync_service_->ProcessRemoteChange(base::Bind( 304 &SetSyncStatusAndUrl, run_loop.QuitClosure(), &status, &url)); 305 run_loop.Run(); 306 return status; 307 } 308 309 int64 GetLargestChangeID() { 310 scoped_ptr<google_apis::AboutResource> about_resource; 311 EXPECT_EQ(google_apis::HTTP_SUCCESS, 312 fake_drive_service_helper()->GetAboutResource(&about_resource)); 313 if (!about_resource) 314 return 0; 315 return about_resource->largest_change_id(); 316 } 317 318 void FetchRemoteChanges() { 319 remote_sync_service_->OnNotificationReceived(); 320 base::RunLoop().RunUntilIdle(); 321 } 322 323 SyncStatusCode ProcessChangesUntilDone() { 324 SyncStatusCode local_sync_status; 325 SyncStatusCode remote_sync_status; 326 while (true) { 327 local_sync_status = ProcessLocalChange(); 328 if (local_sync_status != SYNC_STATUS_OK && 329 local_sync_status != SYNC_STATUS_NO_CHANGE_TO_SYNC && 330 local_sync_status != SYNC_STATUS_FILE_BUSY) 331 return local_sync_status; 332 333 remote_sync_status = ProcessRemoteChange(); 334 if (remote_sync_status != SYNC_STATUS_OK && 335 remote_sync_status != SYNC_STATUS_NO_CHANGE_TO_SYNC && 336 remote_sync_status != SYNC_STATUS_FILE_BUSY) 337 return remote_sync_status; 338 339 if (local_sync_status == SYNC_STATUS_NO_CHANGE_TO_SYNC && 340 remote_sync_status == SYNC_STATUS_NO_CHANGE_TO_SYNC) { 341 remote_sync_service_->PromoteDemotedChanges(); 342 local_sync_service_->PromoteDemotedChanges(); 343 344 if (pending_remote_changes_ || pending_local_changes_) 345 continue; 346 347 base::RunLoop run_loop; 348 int64 largest_fetched_change_id = -1; 349 PostTaskAndReplyWithResult( 350 worker_task_runner_, 351 FROM_HERE, 352 base::Bind(&MetadataDatabase::GetLargestFetchedChangeID, 353 base::Unretained(metadata_database())), 354 base::Bind(&SetValueAndCallClosure<int64>, 355 run_loop.QuitClosure(), 356 &largest_fetched_change_id)); 357 run_loop.Run(); 358 if (largest_fetched_change_id != GetLargestChangeID()) { 359 FetchRemoteChanges(); 360 continue; 361 } 362 break; 363 } 364 } 365 return SYNC_STATUS_OK; 366 } 367 368 // Verifies local and remote files/folders are consistent. 369 // This function checks: 370 // - Each registered origin has corresponding remote folder. 371 // - Each local file/folder has corresponding remote one. 372 // - Each remote file/folder has corresponding local one. 373 // TODO(tzik): Handle conflict case. i.e. allow remote file has different 374 // file content if the corresponding local file conflicts to it. 375 void VerifyConsistency() { 376 std::string sync_root_folder_id; 377 google_apis::GDataErrorCode error = 378 fake_drive_service_helper_->GetSyncRootFolderID(&sync_root_folder_id); 379 if (sync_root_folder_id.empty()) { 380 EXPECT_EQ(google_apis::HTTP_NOT_FOUND, error); 381 EXPECT_TRUE(file_systems_.empty()); 382 return; 383 } 384 EXPECT_EQ(google_apis::HTTP_SUCCESS, error); 385 386 ScopedVector<google_apis::ResourceEntry> remote_entries; 387 EXPECT_EQ(google_apis::HTTP_SUCCESS, 388 fake_drive_service_helper_->ListFilesInFolder( 389 sync_root_folder_id, &remote_entries)); 390 std::map<std::string, const google_apis::ResourceEntry*> app_root_by_title; 391 for (ScopedVector<google_apis::ResourceEntry>::iterator itr = 392 remote_entries.begin(); 393 itr != remote_entries.end(); 394 ++itr) { 395 const google_apis::ResourceEntry& remote_entry = **itr; 396 EXPECT_FALSE(ContainsKey(app_root_by_title, remote_entry.title())); 397 app_root_by_title[remote_entry.title()] = *itr; 398 } 399 400 for (std::map<std::string, CannedSyncableFileSystem*>::const_iterator itr = 401 file_systems_.begin(); 402 itr != file_systems_.end(); ++itr) { 403 const std::string& app_id = itr->first; 404 SCOPED_TRACE(testing::Message() << "Verifying app: " << app_id); 405 CannedSyncableFileSystem* file_system = itr->second; 406 ASSERT_TRUE(ContainsKey(app_root_by_title, app_id)); 407 VerifyConsistencyForFolder( 408 app_id, base::FilePath(), 409 app_root_by_title[app_id]->resource_id(), 410 file_system); 411 } 412 } 413 414 void VerifyConsistencyForFolder(const std::string& app_id, 415 const base::FilePath& path, 416 const std::string& folder_id, 417 CannedSyncableFileSystem* file_system) { 418 SCOPED_TRACE(testing::Message() << "Verifying folder: " << path.value()); 419 420 ScopedVector<google_apis::ResourceEntry> remote_entries; 421 EXPECT_EQ(google_apis::HTTP_SUCCESS, 422 fake_drive_service_helper_->ListFilesInFolder( 423 folder_id, &remote_entries)); 424 std::map<std::string, const google_apis::ResourceEntry*> 425 remote_entry_by_title; 426 for (size_t i = 0; i < remote_entries.size(); ++i) { 427 google_apis::ResourceEntry* remote_entry = remote_entries[i]; 428 EXPECT_FALSE(ContainsKey(remote_entry_by_title, remote_entry->title())) 429 << "title: " << remote_entry->title(); 430 remote_entry_by_title[remote_entry->title()] = remote_entry; 431 } 432 433 fileapi::FileSystemURL url(CreateURL(app_id, path)); 434 FileEntryList local_entries; 435 EXPECT_EQ(base::File::FILE_OK, 436 file_system->ReadDirectory(url, &local_entries)); 437 for (FileEntryList::iterator itr = local_entries.begin(); 438 itr != local_entries.end(); 439 ++itr) { 440 const fileapi::DirectoryEntry& local_entry = *itr; 441 fileapi::FileSystemURL entry_url( 442 CreateURL(app_id, path.Append(local_entry.name))); 443 std::string title = 444 fileapi::VirtualPath::BaseName(entry_url.path()).AsUTF8Unsafe(); 445 SCOPED_TRACE(testing::Message() << "Verifying entry: " << title); 446 447 ASSERT_TRUE(ContainsKey(remote_entry_by_title, title)); 448 const google_apis::ResourceEntry& remote_entry = 449 *remote_entry_by_title[title]; 450 if (local_entry.is_directory) { 451 ASSERT_TRUE(remote_entry.is_folder()); 452 VerifyConsistencyForFolder(app_id, entry_url.path(), 453 remote_entry.resource_id(), 454 file_system); 455 } else { 456 ASSERT_TRUE(remote_entry.is_file()); 457 VerifyConsistencyForFile(app_id, entry_url.path(), 458 remote_entry.resource_id(), 459 file_system); 460 } 461 remote_entry_by_title.erase(title); 462 } 463 464 EXPECT_TRUE(remote_entry_by_title.empty()); 465 } 466 467 void VerifyConsistencyForFile(const std::string& app_id, 468 const base::FilePath& path, 469 const std::string& file_id, 470 CannedSyncableFileSystem* file_system) { 471 fileapi::FileSystemURL url(CreateURL(app_id, path)); 472 std::string file_content; 473 EXPECT_EQ(google_apis::HTTP_SUCCESS, 474 fake_drive_service_helper_->ReadFile(file_id, &file_content)); 475 EXPECT_EQ(base::File::FILE_OK, 476 file_system->VerifyFile(url, file_content)); 477 } 478 479 size_t CountApp() { 480 return file_systems_.size(); 481 } 482 483 size_t CountLocalFile(const std::string& app_id) { 484 if (!ContainsKey(file_systems_, app_id)) 485 return 0; 486 487 CannedSyncableFileSystem* file_system = file_systems_[app_id]; 488 std::stack<base::FilePath> folders; 489 folders.push(base::FilePath()); // root folder 490 491 size_t result = 1; 492 while (!folders.empty()) { 493 fileapi::FileSystemURL url(CreateURL(app_id, folders.top())); 494 folders.pop(); 495 496 FileEntryList entries; 497 EXPECT_EQ(base::File::FILE_OK, 498 file_system->ReadDirectory(url, &entries)); 499 for (FileEntryList::iterator itr = entries.begin(); 500 itr != entries.end(); ++itr) { 501 ++result; 502 if (itr->is_directory) 503 folders.push(url.path().Append(itr->name)); 504 } 505 } 506 507 return result; 508 } 509 510 void VerifyLocalFile(const std::string& app_id, 511 const base::FilePath::StringType& path, 512 const std::string& content) { 513 SCOPED_TRACE(testing::Message() << "Verifying local file: " 514 << "app_id = " << app_id 515 << ", path = " << path); 516 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); 517 EXPECT_EQ(base::File::FILE_OK, 518 file_systems_[app_id]->VerifyFile( 519 CreateURL(app_id, path), content)); 520 } 521 522 void VerifyLocalFolder(const std::string& app_id, 523 const base::FilePath::StringType& path) { 524 SCOPED_TRACE(testing::Message() << "Verifying local file: " 525 << "app_id = " << app_id 526 << ", path = " << path); 527 ASSERT_TRUE(ContainsKey(file_systems_, app_id)); 528 EXPECT_EQ(base::File::FILE_OK, 529 file_systems_[app_id]->DirectoryExists(CreateURL(app_id, path))); 530 } 531 532 size_t CountMetadata() { 533 size_t count = 0; 534 base::RunLoop run_loop; 535 PostTaskAndReplyWithResult( 536 worker_task_runner_, 537 FROM_HERE, 538 base::Bind(&MetadataDatabase::CountFileMetadata, 539 base::Unretained(metadata_database())), 540 base::Bind(&SetValueAndCallClosure<size_t>, 541 run_loop.QuitClosure(), 542 &count)); 543 run_loop.Run(); 544 return count; 545 } 546 547 size_t CountTracker() { 548 size_t count = 0; 549 base::RunLoop run_loop; 550 PostTaskAndReplyWithResult( 551 worker_task_runner_, 552 FROM_HERE, 553 base::Bind(&MetadataDatabase::CountFileTracker, 554 base::Unretained(metadata_database())), 555 base::Bind(&SetValueAndCallClosure<size_t>, 556 run_loop.QuitClosure(), &count)); 557 run_loop.Run(); 558 return count; 559 } 560 561 drive::FakeDriveService* fake_drive_service() { 562 return static_cast<drive::FakeDriveService*>( 563 remote_sync_service_->GetDriveService()); 564 } 565 566 FakeDriveServiceHelper* fake_drive_service_helper() { 567 return fake_drive_service_helper_.get(); 568 } 569 570 private: 571 // NOTE: Member functions of MetadataDatabase class must not be called 572 // directly through this method. Call them via PostTask. 573 MetadataDatabase* metadata_database() { 574 return remote_sync_service_->sync_worker_->GetMetadataDatabase(); 575 } 576 577 content::TestBrowserThreadBundle thread_bundle_; 578 579 base::ScopedTempDir base_dir_; 580 scoped_ptr<leveldb::Env> in_memory_env_; 581 TestingProfile profile_; 582 583 scoped_ptr<SyncEngine> remote_sync_service_; 584 scoped_ptr<LocalFileSyncService> local_sync_service_; 585 586 int64 pending_remote_changes_; 587 int64 pending_local_changes_; 588 589 scoped_ptr<FakeDriveServiceHelper> fake_drive_service_helper_; 590 std::map<std::string, CannedSyncableFileSystem*> file_systems_; 591 592 593 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 594 scoped_refptr<base::SequencedTaskRunner> worker_task_runner_; 595 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; 596 597 DISALLOW_COPY_AND_ASSIGN(DriveBackendSyncTest); 598}; 599 600TEST_F(DriveBackendSyncTest, LocalToRemoteBasicTest) { 601 std::string app_id = "example"; 602 603 RegisterApp(app_id); 604 AddOrUpdateLocalFile(app_id, FPL("file"), "abcde"); 605 606 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 607 VerifyConsistency(); 608 609 EXPECT_EQ(1u, CountApp()); 610 EXPECT_EQ(2u, CountLocalFile(app_id)); 611 VerifyLocalFile(app_id, FPL("file"), "abcde"); 612 613 EXPECT_EQ(3u, CountMetadata()); 614 EXPECT_EQ(3u, CountTracker()); 615} 616 617TEST_F(DriveBackendSyncTest, RemoteToLocalBasicTest) { 618 std::string app_id = "example"; 619 RegisterApp(app_id); 620 621 std::string app_root_folder_id; 622 EXPECT_TRUE(GetAppRootFolderID(app_id, &app_root_folder_id)); 623 624 std::string file_id; 625 EXPECT_EQ(google_apis::HTTP_SUCCESS, 626 fake_drive_service_helper()->AddFile( 627 app_root_folder_id, "file", "abcde", &file_id)); 628 629 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 630 VerifyConsistency(); 631 632 EXPECT_EQ(1u, CountApp()); 633 EXPECT_EQ(2u, CountLocalFile(app_id)); 634 VerifyLocalFile(app_id, FPL("file"), "abcde"); 635 636 EXPECT_EQ(3u, CountMetadata()); 637 EXPECT_EQ(3u, CountTracker()); 638} 639 640TEST_F(DriveBackendSyncTest, LocalFileUpdateTest) { 641 std::string app_id = "example"; 642 const base::FilePath::StringType kPath(FPL("file")); 643 644 RegisterApp(app_id); 645 AddOrUpdateLocalFile(app_id, kPath, "abcde"); 646 647 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 648 VerifyConsistency(); 649 650 UpdateLocalFile(app_id, kPath, "1234567890"); 651 652 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 653 VerifyConsistency(); 654 655 EXPECT_EQ(1u, CountApp()); 656 EXPECT_EQ(2u, CountLocalFile(app_id)); 657 VerifyLocalFile(app_id, FPL("file"), "1234567890"); 658 659 EXPECT_EQ(3u, CountMetadata()); 660 EXPECT_EQ(3u, CountTracker()); 661} 662 663TEST_F(DriveBackendSyncTest, RemoteFileUpdateTest) { 664 std::string app_id = "example"; 665 666 RegisterApp(app_id); 667 std::string remote_file_id; 668 std::string app_root_folder_id; 669 EXPECT_TRUE(GetAppRootFolderID(app_id, &app_root_folder_id)); 670 EXPECT_EQ(google_apis::HTTP_SUCCESS, 671 fake_drive_service_helper()->AddFile( 672 app_root_folder_id, "file", "abcde", &remote_file_id)); 673 674 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 675 VerifyConsistency(); 676 677 EXPECT_EQ(google_apis::HTTP_SUCCESS, 678 fake_drive_service_helper()->UpdateFile( 679 remote_file_id, "1234567890")); 680 681 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 682 VerifyConsistency(); 683 684 EXPECT_EQ(1u, CountApp()); 685 EXPECT_EQ(2u, CountLocalFile(app_id)); 686 VerifyLocalFile(app_id, FPL("file"), "1234567890"); 687 688 EXPECT_EQ(3u, CountMetadata()); 689 EXPECT_EQ(3u, CountTracker()); 690} 691 692TEST_F(DriveBackendSyncTest, LocalFileDeletionTest) { 693 std::string app_id = "example"; 694 const base::FilePath::StringType path(FPL("file")); 695 696 RegisterApp(app_id); 697 AddOrUpdateLocalFile(app_id, path, "abcde"); 698 699 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 700 VerifyConsistency(); 701 702 RemoveLocal(app_id, path); 703 704 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 705 VerifyConsistency(); 706 707 EXPECT_EQ(1u, CountApp()); 708 EXPECT_EQ(1u, CountLocalFile(app_id)); 709 710 EXPECT_EQ(2u, CountMetadata()); 711 EXPECT_EQ(2u, CountTracker()); 712} 713 714TEST_F(DriveBackendSyncTest, RemoteFileDeletionTest) { 715 std::string app_id = "example"; 716 const base::FilePath::StringType path(FPL("file")); 717 718 RegisterApp(app_id); 719 AddOrUpdateLocalFile(app_id, path, "abcde"); 720 721 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 722 VerifyConsistency(); 723 724 std::string file_id = GetFileIDByPath(app_id, path); 725 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 726 fake_drive_service_helper()->DeleteResource(file_id)); 727 728 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 729 VerifyConsistency(); 730 731 EXPECT_EQ(1u, CountApp()); 732 EXPECT_EQ(1u, CountLocalFile(app_id)); 733 734 EXPECT_EQ(2u, CountMetadata()); 735 EXPECT_EQ(2u, CountTracker()); 736} 737 738TEST_F(DriveBackendSyncTest, RemoteRenameTest) { 739 std::string app_id = "example"; 740 const base::FilePath::StringType path(FPL("file")); 741 742 RegisterApp(app_id); 743 AddOrUpdateLocalFile(app_id, path, "abcde"); 744 745 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 746 VerifyConsistency(); 747 748 std::string file_id = GetFileIDByPath(app_id, path); 749 EXPECT_EQ(google_apis::HTTP_SUCCESS, 750 fake_drive_service_helper()->RenameResource( 751 file_id, "renamed_file")); 752 753 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 754 VerifyConsistency(); 755 756 EXPECT_EQ(1u, CountApp()); 757 EXPECT_EQ(2u, CountLocalFile(app_id)); 758 VerifyLocalFile(app_id, FPL("renamed_file"), "abcde"); 759 760 EXPECT_EQ(3u, CountMetadata()); 761 EXPECT_EQ(3u, CountTracker()); 762} 763 764TEST_F(DriveBackendSyncTest, RemoteRenameAndRevertTest) { 765 std::string app_id = "example"; 766 const base::FilePath::StringType path(FPL("file")); 767 768 RegisterApp(app_id); 769 AddOrUpdateLocalFile(app_id, path, "abcde"); 770 771 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 772 VerifyConsistency(); 773 774 std::string file_id = GetFileIDByPath(app_id, path); 775 EXPECT_EQ(google_apis::HTTP_SUCCESS, 776 fake_drive_service_helper()->RenameResource( 777 file_id, "renamed_file")); 778 779 FetchRemoteChanges(); 780 781 EXPECT_EQ(google_apis::HTTP_SUCCESS, 782 fake_drive_service_helper()->RenameResource( 783 file_id, base::FilePath(path).AsUTF8Unsafe())); 784 785 FetchRemoteChanges(); 786 787 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 788 VerifyConsistency(); 789 790 EXPECT_EQ(1u, CountApp()); 791 EXPECT_EQ(2u, CountLocalFile(app_id)); 792 VerifyLocalFile(app_id, FPL("file"), "abcde"); 793 794 EXPECT_EQ(3u, CountMetadata()); 795 EXPECT_EQ(3u, CountTracker()); 796} 797 798TEST_F(DriveBackendSyncTest, ReorganizeToOtherFolder) { 799 std::string app_id = "example"; 800 const base::FilePath::StringType path(FPL("file")); 801 802 RegisterApp(app_id); 803 AddLocalFolder(app_id, FPL("folder_src")); 804 AddLocalFolder(app_id, FPL("folder_dest")); 805 AddOrUpdateLocalFile(app_id, FPL("folder_src/file"), "abcde"); 806 807 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 808 VerifyConsistency(); 809 810 std::string file_id = GetFileIDByPath(app_id, FPL("folder_src/file")); 811 std::string src_folder_id = GetFileIDByPath(app_id, FPL("folder_src")); 812 std::string dest_folder_id = GetFileIDByPath(app_id, FPL("folder_dest")); 813 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 814 fake_drive_service_helper()->RemoveResourceFromDirectory( 815 src_folder_id, file_id)); 816 EXPECT_EQ(google_apis::HTTP_SUCCESS, 817 fake_drive_service_helper()->AddResourceToDirectory( 818 dest_folder_id, file_id)); 819 820 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 821 VerifyConsistency(); 822 823 EXPECT_EQ(1u, CountApp()); 824 EXPECT_EQ(4u, CountLocalFile(app_id)); 825 VerifyLocalFolder(app_id, FPL("folder_dest")); 826 VerifyLocalFile(app_id, FPL("folder_dest/file"), "abcde"); 827 828 EXPECT_EQ(5u, CountMetadata()); 829 EXPECT_EQ(5u, CountTracker()); 830} 831 832TEST_F(DriveBackendSyncTest, ReorganizeToOtherApp) { 833 std::string src_app_id = "src_app"; 834 std::string dest_app_id = "dest_app"; 835 836 RegisterApp(src_app_id); 837 RegisterApp(dest_app_id); 838 839 AddLocalFolder(src_app_id, FPL("folder_src")); 840 AddLocalFolder(dest_app_id, FPL("folder_dest")); 841 AddOrUpdateLocalFile(src_app_id, FPL("folder_src/file"), "abcde"); 842 843 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 844 VerifyConsistency(); 845 846 std::string file_id = GetFileIDByPath(src_app_id, FPL("folder_src/file")); 847 std::string src_folder_id = GetFileIDByPath(src_app_id, FPL("folder_src")); 848 std::string dest_folder_id = GetFileIDByPath(dest_app_id, FPL("folder_dest")); 849 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 850 fake_drive_service_helper()->RemoveResourceFromDirectory( 851 src_folder_id, file_id)); 852 EXPECT_EQ(google_apis::HTTP_SUCCESS, 853 fake_drive_service_helper()->AddResourceToDirectory( 854 dest_folder_id, file_id)); 855 856 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 857 VerifyConsistency(); 858 859 EXPECT_EQ(2u, CountApp()); 860 EXPECT_EQ(2u, CountLocalFile(src_app_id)); 861 EXPECT_EQ(3u, CountLocalFile(dest_app_id)); 862 VerifyLocalFile(dest_app_id, FPL("folder_dest/file"), "abcde"); 863 864 EXPECT_EQ(6u, CountMetadata()); 865 EXPECT_EQ(6u, CountTracker()); 866} 867 868TEST_F(DriveBackendSyncTest, ReorganizeToUnmanagedArea) { 869 std::string app_id = "example"; 870 871 RegisterApp(app_id); 872 873 AddLocalFolder(app_id, FPL("folder_src")); 874 AddOrUpdateLocalFile(app_id, FPL("folder_src/file_orphaned"), "abcde"); 875 AddOrUpdateLocalFile(app_id, FPL("folder_src/file_under_sync_root"), "123"); 876 AddOrUpdateLocalFile(app_id, FPL("folder_src/file_under_drive_root"), "hoge"); 877 878 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 879 VerifyConsistency(); 880 881 std::string file_orphaned_id = 882 GetFileIDByPath(app_id, FPL("folder_src/file_orphaned")); 883 std::string file_under_sync_root_id = 884 GetFileIDByPath(app_id, FPL("folder_src/file_under_sync_root")); 885 std::string file_under_drive_root_id = 886 GetFileIDByPath(app_id, FPL("folder_src/file_under_drive_root")); 887 888 std::string folder_id = GetFileIDByPath(app_id, FPL("folder_src")); 889 std::string sync_root_folder_id; 890 EXPECT_EQ(google_apis::HTTP_SUCCESS, 891 fake_drive_service_helper()->GetSyncRootFolderID( 892 &sync_root_folder_id)); 893 894 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 895 fake_drive_service_helper()->RemoveResourceFromDirectory( 896 folder_id, file_orphaned_id)); 897 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 898 fake_drive_service_helper()->RemoveResourceFromDirectory( 899 folder_id, file_under_sync_root_id)); 900 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 901 fake_drive_service_helper()->RemoveResourceFromDirectory( 902 folder_id, file_under_drive_root_id)); 903 904 EXPECT_EQ(google_apis::HTTP_SUCCESS, 905 fake_drive_service_helper()->AddResourceToDirectory( 906 sync_root_folder_id, file_under_sync_root_id)); 907 EXPECT_EQ(google_apis::HTTP_SUCCESS, 908 fake_drive_service_helper()->AddResourceToDirectory( 909 fake_drive_service()->GetRootResourceId(), 910 file_under_drive_root_id)); 911 912 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 913 VerifyConsistency(); 914 915 EXPECT_EQ(1u, CountApp()); 916 EXPECT_EQ(2u, CountLocalFile(app_id)); 917 918 EXPECT_EQ(4u, CountMetadata()); 919 EXPECT_EQ(4u, CountTracker()); 920} 921 922TEST_F(DriveBackendSyncTest, ReorganizeToMultipleParents) { 923 std::string app_id = "example"; 924 925 RegisterApp(app_id); 926 927 AddLocalFolder(app_id, FPL("parent1")); 928 AddLocalFolder(app_id, FPL("parent2")); 929 AddOrUpdateLocalFile(app_id, FPL("parent1/file"), "abcde"); 930 931 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 932 VerifyConsistency(); 933 934 std::string file_id = GetFileIDByPath(app_id, FPL("parent1/file")); 935 std::string parent2_folder_id = GetFileIDByPath(app_id, FPL("parent2")); 936 EXPECT_EQ(google_apis::HTTP_SUCCESS, 937 fake_drive_service_helper()->AddResourceToDirectory( 938 parent2_folder_id, file_id)); 939 940 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 941 VerifyConsistency(); 942 943 EXPECT_EQ(1u, CountApp()); 944 EXPECT_EQ(4u, CountLocalFile(app_id)); 945 VerifyLocalFolder(app_id, FPL("parent1")); 946 VerifyLocalFolder(app_id, FPL("parent2")); 947 VerifyLocalFile(app_id, FPL("parent1/file"), "abcde"); 948 949 EXPECT_EQ(5u, CountMetadata()); 950 EXPECT_EQ(5u, CountTracker()); 951} 952 953TEST_F(DriveBackendSyncTest, ReorganizeAndRevert) { 954 std::string app_id = "example"; 955 956 RegisterApp(app_id); 957 958 AddLocalFolder(app_id, FPL("folder")); 959 AddLocalFolder(app_id, FPL("folder_temp")); 960 AddOrUpdateLocalFile(app_id, FPL("folder/file"), "abcde"); 961 962 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 963 VerifyConsistency(); 964 965 std::string file_id = GetFileIDByPath(app_id, FPL("folder/file")); 966 std::string folder_id = GetFileIDByPath(app_id, FPL("folder")); 967 std::string folder_temp_id = GetFileIDByPath(app_id, FPL("folder_temp")); 968 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 969 fake_drive_service_helper()->RemoveResourceFromDirectory( 970 folder_id, file_id)); 971 EXPECT_EQ(google_apis::HTTP_SUCCESS, 972 fake_drive_service_helper()->AddResourceToDirectory( 973 folder_temp_id, file_id)); 974 975 FetchRemoteChanges(); 976 977 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 978 fake_drive_service_helper()->RemoveResourceFromDirectory( 979 folder_temp_id, file_id)); 980 EXPECT_EQ(google_apis::HTTP_SUCCESS, 981 fake_drive_service_helper()->AddResourceToDirectory( 982 folder_id, file_id)); 983 984 FetchRemoteChanges(); 985 986 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 987 VerifyConsistency(); 988 989 EXPECT_EQ(1u, CountApp()); 990 EXPECT_EQ(4u, CountLocalFile(app_id)); 991 VerifyLocalFolder(app_id, FPL("folder")); 992 VerifyLocalFile(app_id, FPL("folder/file"), "abcde"); 993 994 EXPECT_EQ(5u, CountMetadata()); 995 EXPECT_EQ(5u, CountTracker()); 996} 997 998TEST_F(DriveBackendSyncTest, ConflictTest_AddFolder_AddFolder) { 999 std::string app_id = "example"; 1000 1001 RegisterApp(app_id); 1002 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL("")); 1003 1004 AddLocalFolder(app_id, FPL("conflict_to_pending_remote")); 1005 AddLocalFolder(app_id, FPL("conflict_to_existing_remote")); 1006 1007 std::string remote_folder_id; 1008 EXPECT_EQ(google_apis::HTTP_CREATED, 1009 fake_drive_service_helper()->AddFolder( 1010 app_root_folder_id, 1011 "conflict_to_pending_remote", &remote_folder_id)); 1012 1013 FetchRemoteChanges(); 1014 1015 EXPECT_EQ(google_apis::HTTP_CREATED, 1016 fake_drive_service_helper()->AddFolder( 1017 app_root_folder_id, 1018 "conflict_to_existing_remote", &remote_folder_id)); 1019 1020 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1021 VerifyConsistency(); 1022 1023 EXPECT_EQ(1u, CountApp()); 1024 EXPECT_EQ(3u, CountLocalFile(app_id)); 1025 VerifyLocalFolder(app_id, FPL("conflict_to_pending_remote")); 1026 VerifyLocalFolder(app_id, FPL("conflict_to_existing_remote")); 1027 1028 EXPECT_EQ(4u, CountMetadata()); 1029 EXPECT_EQ(4u, CountTracker()); 1030} 1031 1032TEST_F(DriveBackendSyncTest, ConflictTest_AddFolder_DeleteFolder) { 1033 std::string app_id = "example"; 1034 1035 RegisterApp(app_id); 1036 1037 AddLocalFolder(app_id, FPL("conflict_to_pending_remote")); 1038 AddLocalFolder(app_id, FPL("conflict_to_existing_remote")); 1039 1040 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1041 VerifyConsistency(); 1042 1043 // Test body starts from here. 1044 RemoveLocal(app_id, FPL("conflict_to_pending_remote")); 1045 AddLocalFolder(app_id, FPL("conflict_to_pending_remote")); 1046 RemoveLocal(app_id, FPL("conflict_to_existing_remote")); 1047 AddLocalFolder(app_id, FPL("conflict_to_existing_remote")); 1048 1049 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 1050 fake_drive_service_helper()->DeleteResource( 1051 GetFileIDByPath(app_id, FPL("conflict_to_pending_remote")))); 1052 1053 FetchRemoteChanges(); 1054 1055 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 1056 fake_drive_service_helper()->DeleteResource( 1057 GetFileIDByPath(app_id, FPL("conflict_to_existing_remote")))); 1058 1059 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1060 VerifyConsistency(); 1061 1062 EXPECT_EQ(1u, CountApp()); 1063 EXPECT_EQ(2u, CountLocalFile(app_id)); 1064 VerifyLocalFolder(app_id, FPL("conflict_to_pending_remote")); 1065 1066 EXPECT_EQ(3u, CountMetadata()); 1067 EXPECT_EQ(3u, CountTracker()); 1068} 1069 1070TEST_F(DriveBackendSyncTest, ConflictTest_AddFolder_AddFile) { 1071 std::string app_id = "example"; 1072 1073 RegisterApp(app_id); 1074 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL("")); 1075 1076 AddLocalFolder(app_id, FPL("conflict_to_pending_remote")); 1077 AddLocalFolder(app_id, FPL("conflict_to_existing_remote")); 1078 1079 std::string file_id; 1080 EXPECT_EQ(google_apis::HTTP_SUCCESS, 1081 fake_drive_service_helper()->AddFile( 1082 app_root_folder_id, "conflict_to_pending_remote", "foo", 1083 &file_id)); 1084 EXPECT_EQ(google_apis::HTTP_SUCCESS, 1085 fake_drive_service_helper()->UpdateModificationTime( 1086 file_id, 1087 base::Time::Now() + base::TimeDelta::FromDays(1))); 1088 1089 FetchRemoteChanges(); 1090 1091 EXPECT_EQ(google_apis::HTTP_SUCCESS, 1092 fake_drive_service_helper()->AddFile( 1093 app_root_folder_id, "conflict_to_existing_remote", "foo", 1094 &file_id)); 1095 EXPECT_EQ(google_apis::HTTP_SUCCESS, 1096 fake_drive_service_helper()->UpdateModificationTime( 1097 file_id, 1098 base::Time::Now() + base::TimeDelta::FromDays(1))); 1099 1100 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1101 VerifyConsistency(); 1102 1103 EXPECT_EQ(1u, CountApp()); 1104 EXPECT_EQ(3u, CountLocalFile(app_id)); 1105 VerifyLocalFolder(app_id, FPL("conflict_to_pending_remote")); 1106 VerifyLocalFolder(app_id, FPL("conflict_to_existing_remote")); 1107 1108 EXPECT_EQ(4u, CountMetadata()); 1109 EXPECT_EQ(4u, CountTracker()); 1110} 1111 1112TEST_F(DriveBackendSyncTest, ConflictTest_AddFolder_DeleteFile) { 1113 std::string app_id = "example"; 1114 1115 RegisterApp(app_id); 1116 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL("")); 1117 1118 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo"); 1119 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar"); 1120 1121 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1122 VerifyConsistency(); 1123 1124 // Test body starts from here. 1125 RemoveLocal(app_id, FPL("conflict_to_pending_remote")); 1126 AddLocalFolder(app_id, FPL("conflict_to_pending_remote")); 1127 1128 RemoveLocal(app_id, FPL("conflict_to_existing_remote")); 1129 AddLocalFolder(app_id, FPL("conflict_to_existing_remote")); 1130 1131 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 1132 fake_drive_service_helper()->DeleteResource( 1133 GetFileIDByPath(app_id, FPL("conflict_to_pending_remote")))); 1134 1135 FetchRemoteChanges(); 1136 1137 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 1138 fake_drive_service_helper()->DeleteResource( 1139 GetFileIDByPath(app_id, FPL("conflict_to_existing_remote")))); 1140 1141 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1142 VerifyConsistency(); 1143 1144 EXPECT_EQ(1u, CountApp()); 1145 EXPECT_EQ(3u, CountLocalFile(app_id)); 1146 VerifyLocalFolder(app_id, FPL("conflict_to_pending_remote")); 1147 VerifyLocalFolder(app_id, FPL("conflict_to_existing_remote")); 1148 1149 EXPECT_EQ(4u, CountMetadata()); 1150 EXPECT_EQ(4u, CountTracker()); 1151} 1152 1153TEST_F(DriveBackendSyncTest, ConflictTest_DeleteFolder_AddFolder) { 1154 std::string app_id = "example"; 1155 1156 RegisterApp(app_id); 1157 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL("")); 1158 AddLocalFolder(app_id, FPL("conflict_to_pending_remote")); 1159 AddLocalFolder(app_id, FPL("conflict_to_existing_remote")); 1160 1161 RemoveLocal(app_id, FPL("conflict_to_pending_remote")); 1162 RemoveLocal(app_id, FPL("conflict_to_existing_remote")); 1163 1164 std::string file_id; 1165 EXPECT_EQ(google_apis::HTTP_CREATED, 1166 fake_drive_service_helper()->AddFolder( 1167 app_root_folder_id, 1168 "conflict_to_pending_remote", &file_id)); 1169 1170 FetchRemoteChanges(); 1171 1172 EXPECT_EQ(google_apis::HTTP_CREATED, 1173 fake_drive_service_helper()->AddFolder( 1174 app_root_folder_id, 1175 "conflict_to_existing_remote", NULL)); 1176 1177 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1178 VerifyConsistency(); 1179 1180 EXPECT_EQ(1u, CountApp()); 1181 EXPECT_EQ(3u, CountLocalFile(app_id)); 1182 VerifyLocalFolder(app_id, FPL("conflict_to_pending_remote")); 1183 VerifyLocalFolder(app_id, FPL("conflict_to_existing_remote")); 1184 1185 EXPECT_EQ(4u, CountMetadata()); 1186 EXPECT_EQ(4u, CountTracker()); 1187} 1188 1189TEST_F(DriveBackendSyncTest, ConflictTest_DeleteFolder_DeleteFolder) { 1190 std::string app_id = "example"; 1191 1192 RegisterApp(app_id); 1193 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL("")); 1194 1195 AddLocalFolder(app_id, FPL("conflict_to_pending_remote")); 1196 AddLocalFolder(app_id, FPL("conflict_to_existing_remote")); 1197 1198 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1199 VerifyConsistency(); 1200 1201 // Test body starts from here. 1202 RemoveLocal(app_id, FPL("conflict_to_pending_remote")); 1203 RemoveLocal(app_id, FPL("conflict_to_existing_remote")); 1204 1205 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 1206 fake_drive_service_helper()->DeleteResource( 1207 GetFileIDByPath(app_id, FPL("conflict_to_pending_remote")))); 1208 1209 FetchRemoteChanges(); 1210 1211 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 1212 fake_drive_service_helper()->DeleteResource( 1213 GetFileIDByPath(app_id, FPL("conflict_to_existing_remote")))); 1214 1215 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1216 VerifyConsistency(); 1217 1218 EXPECT_EQ(1u, CountApp()); 1219 EXPECT_EQ(1u, CountLocalFile(app_id)); 1220 1221 EXPECT_EQ(2u, CountMetadata()); 1222 EXPECT_EQ(2u, CountTracker()); 1223} 1224 1225TEST_F(DriveBackendSyncTest, ConflictTest_DeleteFolder_AddFile) { 1226 std::string app_id = "example"; 1227 1228 RegisterApp(app_id); 1229 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL("")); 1230 1231 AddLocalFolder(app_id, FPL("conflict_to_pending_remote")); 1232 AddLocalFolder(app_id, FPL("conflict_to_existing_remote")); 1233 RemoveLocal(app_id, FPL("conflict_to_pending_remote")); 1234 RemoveLocal(app_id, FPL("conflict_to_existing_remote")); 1235 1236 EXPECT_EQ(google_apis::HTTP_SUCCESS, 1237 fake_drive_service_helper()->AddFile( 1238 app_root_folder_id, "conflict_to_pending_remote", "foo", NULL)); 1239 1240 FetchRemoteChanges(); 1241 1242 EXPECT_EQ(google_apis::HTTP_SUCCESS, 1243 fake_drive_service_helper()->AddFile( 1244 app_root_folder_id, "conflict_to_existing_remote", "bar", 1245 NULL)); 1246 1247 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1248 VerifyConsistency(); 1249 1250 EXPECT_EQ(1u, CountApp()); 1251 EXPECT_EQ(3u, CountLocalFile(app_id)); 1252 VerifyLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo"); 1253 VerifyLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar"); 1254 1255 EXPECT_EQ(4u, CountMetadata()); 1256 EXPECT_EQ(4u, CountTracker()); 1257} 1258 1259TEST_F(DriveBackendSyncTest, ConflictTest_DeleteFolder_DeleteFile) { 1260 std::string app_id = "example"; 1261 1262 RegisterApp(app_id); 1263 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL("")); 1264 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo"); 1265 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar"); 1266 1267 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1268 VerifyConsistency(); 1269 1270 // Test body starts from here. 1271 RemoveLocal(app_id, FPL("conflict_to_pending_remote")); 1272 RemoveLocal(app_id, FPL("conflict_to_existing_remote")); 1273 1274 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 1275 fake_drive_service_helper()->DeleteResource( 1276 GetFileIDByPath(app_id, FPL("conflict_to_pending_remote")))); 1277 1278 FetchRemoteChanges(); 1279 1280 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 1281 fake_drive_service_helper()->DeleteResource( 1282 GetFileIDByPath(app_id, FPL("conflict_to_existing_remote")))); 1283 1284 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1285 VerifyConsistency(); 1286 1287 EXPECT_EQ(1u, CountApp()); 1288 EXPECT_EQ(1u, CountLocalFile(app_id)); 1289 1290 EXPECT_EQ(2u, CountMetadata()); 1291 EXPECT_EQ(2u, CountTracker()); 1292} 1293 1294TEST_F(DriveBackendSyncTest, ConflictTest_AddFile_AddFolder) { 1295 std::string app_id = "example"; 1296 1297 RegisterApp(app_id); 1298 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL("")); 1299 1300 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo"); 1301 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar"); 1302 1303 std::string file_id; 1304 EXPECT_EQ(google_apis::HTTP_CREATED, 1305 fake_drive_service_helper()->AddFolder( 1306 app_root_folder_id, "conflict_to_pending_remote", 1307 &file_id)); 1308 EXPECT_EQ(google_apis::HTTP_SUCCESS, 1309 fake_drive_service_helper()->UpdateModificationTime( 1310 file_id, 1311 base::Time::Now() - base::TimeDelta::FromDays(1))); 1312 1313 FetchRemoteChanges(); 1314 1315 EXPECT_EQ(google_apis::HTTP_CREATED, 1316 fake_drive_service_helper()->AddFolder( 1317 app_root_folder_id, "conflict_to_existing_remote", 1318 &file_id)); 1319 EXPECT_EQ(google_apis::HTTP_SUCCESS, 1320 fake_drive_service_helper()->UpdateModificationTime( 1321 file_id, 1322 base::Time::Now() - base::TimeDelta::FromDays(1))); 1323 1324 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1325 VerifyConsistency(); 1326 1327 EXPECT_EQ(1u, CountApp()); 1328 EXPECT_EQ(3u, CountLocalFile(app_id)); 1329 VerifyLocalFolder(app_id, FPL("conflict_to_pending_remote")); 1330 VerifyLocalFolder(app_id, FPL("conflict_to_existing_remote")); 1331 1332 EXPECT_EQ(4u, CountMetadata()); 1333 EXPECT_EQ(4u, CountTracker()); 1334} 1335 1336TEST_F(DriveBackendSyncTest, ConflictTest_AddFile_DeleteFolder) { 1337 std::string app_id = "example"; 1338 1339 RegisterApp(app_id); 1340 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL("")); 1341 1342 AddLocalFolder(app_id, FPL("conflict_to_pending_remote")); 1343 AddLocalFolder(app_id, FPL("conflict_to_existing_remote")); 1344 1345 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1346 VerifyConsistency(); 1347 1348 // Test body starts from here. 1349 RemoveLocal(app_id, FPL("conflict_to_pending_remote")); 1350 RemoveLocal(app_id, FPL("conflict_to_existing_remote")); 1351 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo"); 1352 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar"); 1353 1354 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 1355 fake_drive_service_helper()->DeleteResource( 1356 GetFileIDByPath(app_id, FPL("conflict_to_pending_remote")))); 1357 1358 FetchRemoteChanges(); 1359 1360 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 1361 fake_drive_service_helper()->DeleteResource( 1362 GetFileIDByPath(app_id, FPL("conflict_to_existing_remote")))); 1363 1364 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1365 VerifyConsistency(); 1366 1367 EXPECT_EQ(1u, CountApp()); 1368 EXPECT_EQ(3u, CountLocalFile(app_id)); 1369 VerifyLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo"); 1370 VerifyLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar"); 1371 1372 EXPECT_EQ(4u, CountMetadata()); 1373 EXPECT_EQ(4u, CountTracker()); 1374} 1375 1376TEST_F(DriveBackendSyncTest, ConflictTest_AddFile_AddFile) { 1377 std::string app_id = "example"; 1378 1379 RegisterApp(app_id); 1380 1381 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL("")); 1382 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "hoge"); 1383 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "fuga"); 1384 1385 std::string file_id; 1386 EXPECT_EQ(google_apis::HTTP_SUCCESS, 1387 fake_drive_service_helper()->AddFile( 1388 app_root_folder_id, "conflict_to_pending_remote", "foo", 1389 &file_id)); 1390 EXPECT_EQ(google_apis::HTTP_SUCCESS, 1391 fake_drive_service_helper()->UpdateModificationTime( 1392 file_id, 1393 base::Time::Now() + base::TimeDelta::FromDays(1))); 1394 1395 FetchRemoteChanges(); 1396 1397 EXPECT_EQ(google_apis::HTTP_SUCCESS, 1398 fake_drive_service_helper()->AddFile( 1399 app_root_folder_id, "conflict_to_existing_remote", "bar", 1400 &file_id)); 1401 EXPECT_EQ(google_apis::HTTP_SUCCESS, 1402 fake_drive_service_helper()->UpdateModificationTime( 1403 file_id, 1404 base::Time::Now() + base::TimeDelta::FromDays(1))); 1405 1406 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1407 VerifyConsistency(); 1408 1409 EXPECT_EQ(1u, CountApp()); 1410 EXPECT_EQ(3u, CountLocalFile(app_id)); 1411 VerifyLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo"); 1412 VerifyLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar"); 1413 1414 EXPECT_EQ(4u, CountMetadata()); 1415 EXPECT_EQ(4u, CountTracker()); 1416} 1417 1418TEST_F(DriveBackendSyncTest, ConflictTest_AddFile_DeleteFile) { 1419 std::string app_id = "example"; 1420 1421 RegisterApp(app_id); 1422 1423 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo"); 1424 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar"); 1425 1426 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1427 VerifyConsistency(); 1428 1429 // Test body starts from here. 1430 RemoveLocal(app_id, FPL("conflict_to_pending_remote")); 1431 RemoveLocal(app_id, FPL("conflict_to_existing_remote")); 1432 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "hoge"); 1433 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "fuga"); 1434 1435 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 1436 fake_drive_service_helper()->DeleteResource( 1437 GetFileIDByPath(app_id, FPL("conflict_to_pending_remote")))); 1438 1439 FetchRemoteChanges(); 1440 1441 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 1442 fake_drive_service_helper()->DeleteResource( 1443 GetFileIDByPath(app_id, FPL("conflict_to_existing_remote")))); 1444 1445 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1446 VerifyConsistency(); 1447 1448 EXPECT_EQ(1u, CountApp()); 1449 EXPECT_EQ(3u, CountLocalFile(app_id)); 1450 VerifyLocalFile(app_id, FPL("conflict_to_pending_remote"), "hoge"); 1451 VerifyLocalFile(app_id, FPL("conflict_to_existing_remote"), "fuga"); 1452 1453 EXPECT_EQ(4u, CountMetadata()); 1454 EXPECT_EQ(4u, CountTracker()); 1455} 1456 1457TEST_F(DriveBackendSyncTest, ConflictTest_UpdateFile_DeleteFile) { 1458 std::string app_id = "example"; 1459 1460 RegisterApp(app_id); 1461 1462 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo"); 1463 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar"); 1464 1465 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1466 VerifyConsistency(); 1467 1468 // Test body starts from here. 1469 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "hoge"); 1470 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "fuga"); 1471 1472 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 1473 fake_drive_service_helper()->DeleteResource( 1474 GetFileIDByPath(app_id, FPL("conflict_to_pending_remote")))); 1475 1476 FetchRemoteChanges(); 1477 1478 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 1479 fake_drive_service_helper()->DeleteResource( 1480 GetFileIDByPath(app_id, FPL("conflict_to_existing_remote")))); 1481 1482 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1483 VerifyConsistency(); 1484 1485 EXPECT_EQ(1u, CountApp()); 1486 EXPECT_EQ(3u, CountLocalFile(app_id)); 1487 VerifyLocalFile(app_id, FPL("conflict_to_pending_remote"), "hoge"); 1488 VerifyLocalFile(app_id, FPL("conflict_to_existing_remote"), "fuga"); 1489 1490 EXPECT_EQ(4u, CountMetadata()); 1491 EXPECT_EQ(4u, CountTracker()); 1492} 1493 1494TEST_F(DriveBackendSyncTest, ConflictTest_DeleteFile_AddFolder) { 1495 std::string app_id = "example"; 1496 1497 RegisterApp(app_id); 1498 1499 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL("")); 1500 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo"); 1501 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar"); 1502 1503 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1504 VerifyConsistency(); 1505 1506 // Test body starts from here. 1507 RemoveLocal(app_id, FPL("conflict_to_pending_remote")); 1508 RemoveLocal(app_id, FPL("conflict_to_existing_remote")); 1509 1510 EXPECT_EQ(google_apis::HTTP_CREATED, 1511 fake_drive_service_helper()->AddFolder( 1512 app_root_folder_id, "conflict_to_pending_remote", NULL)); 1513 1514 FetchRemoteChanges(); 1515 1516 EXPECT_EQ(google_apis::HTTP_CREATED, 1517 fake_drive_service_helper()->AddFolder( 1518 app_root_folder_id, "conflict_to_existing_remote", NULL)); 1519 1520 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1521 VerifyConsistency(); 1522 1523 EXPECT_EQ(1u, CountApp()); 1524 EXPECT_EQ(3u, CountLocalFile(app_id)); 1525 VerifyLocalFolder(app_id, FPL("conflict_to_pending_remote")); 1526 VerifyLocalFolder(app_id, FPL("conflict_to_existing_remote")); 1527 1528 EXPECT_EQ(4u, CountMetadata()); 1529 EXPECT_EQ(4u, CountTracker()); 1530} 1531 1532TEST_F(DriveBackendSyncTest, ConflictTest_DeleteFile_DeleteFolder) { 1533 std::string app_id = "example"; 1534 1535 RegisterApp(app_id); 1536 1537 AddLocalFolder(app_id, FPL("conflict_to_pending_remote")); 1538 AddLocalFolder(app_id, FPL("conflict_to_existing_remote")); 1539 1540 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1541 VerifyConsistency(); 1542 1543 // Test body starts from here. 1544 RemoveLocal(app_id, FPL("conflict_to_pending_remote")); 1545 RemoveLocal(app_id, FPL("conflict_to_existing_remote")); 1546 1547 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo"); 1548 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar"); 1549 1550 RemoveLocal(app_id, FPL("conflict_to_pending_remote")); 1551 RemoveLocal(app_id, FPL("conflict_to_existing_remote")); 1552 1553 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 1554 fake_drive_service_helper()->DeleteResource( 1555 GetFileIDByPath(app_id, FPL("conflict_to_pending_remote")))); 1556 1557 FetchRemoteChanges(); 1558 1559 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 1560 fake_drive_service_helper()->DeleteResource( 1561 GetFileIDByPath(app_id, FPL("conflict_to_existing_remote")))); 1562 1563 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1564 VerifyConsistency(); 1565 1566 EXPECT_EQ(1u, CountApp()); 1567 EXPECT_EQ(1u, CountLocalFile(app_id)); 1568 1569 EXPECT_EQ(2u, CountMetadata()); 1570 EXPECT_EQ(2u, CountTracker()); 1571} 1572 1573TEST_F(DriveBackendSyncTest, ConflictTest_DeleteFile_AddFile) { 1574 std::string app_id = "example"; 1575 1576 RegisterApp(app_id); 1577 1578 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL("")); 1579 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo"); 1580 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar"); 1581 RemoveLocal(app_id, FPL("conflict_to_pending_remote")); 1582 RemoveLocal(app_id, FPL("conflict_to_existing_remote")); 1583 1584 EXPECT_EQ(google_apis::HTTP_SUCCESS, 1585 fake_drive_service_helper()->AddFile( 1586 app_root_folder_id, "conflict_to_pending_remote", "hoge", 1587 NULL)); 1588 1589 FetchRemoteChanges(); 1590 1591 EXPECT_EQ(google_apis::HTTP_SUCCESS, 1592 fake_drive_service_helper()->AddFile( 1593 app_root_folder_id, "conflict_to_existing_remote", "fuga", 1594 NULL)); 1595 1596 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1597 VerifyConsistency(); 1598 1599 EXPECT_EQ(1u, CountApp()); 1600 EXPECT_EQ(3u, CountLocalFile(app_id)); 1601 VerifyLocalFile(app_id, FPL("conflict_to_pending_remote"), "hoge"); 1602 VerifyLocalFile(app_id, FPL("conflict_to_existing_remote"), "fuga"); 1603 1604 EXPECT_EQ(4u, CountMetadata()); 1605 EXPECT_EQ(4u, CountTracker()); 1606} 1607 1608TEST_F(DriveBackendSyncTest, ConflictTest_DeleteFile_UpdateFile) { 1609 std::string app_id = "example"; 1610 1611 RegisterApp(app_id); 1612 1613 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL("")); 1614 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo"); 1615 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar"); 1616 1617 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1618 VerifyConsistency(); 1619 1620 // Test body starts from here. 1621 RemoveLocal(app_id, FPL("conflict_to_pending_remote")); 1622 RemoveLocal(app_id, FPL("conflict_to_existing_remote")); 1623 1624 EXPECT_EQ(google_apis::HTTP_SUCCESS, 1625 fake_drive_service_helper()->UpdateFile( 1626 GetFileIDByPath(app_id, FPL("conflict_to_pending_remote")), 1627 "hoge")); 1628 1629 FetchRemoteChanges(); 1630 1631 EXPECT_EQ(google_apis::HTTP_SUCCESS, 1632 fake_drive_service_helper()->UpdateFile( 1633 GetFileIDByPath(app_id, FPL("conflict_to_existing_remote")), 1634 "fuga")); 1635 1636 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1637 VerifyConsistency(); 1638 1639 EXPECT_EQ(1u, CountApp()); 1640 EXPECT_EQ(3u, CountLocalFile(app_id)); 1641 VerifyLocalFile(app_id, FPL("conflict_to_pending_remote"), "hoge"); 1642 VerifyLocalFile(app_id, FPL("conflict_to_existing_remote"), "fuga"); 1643 1644 EXPECT_EQ(4u, CountMetadata()); 1645 EXPECT_EQ(4u, CountTracker()); 1646} 1647 1648TEST_F(DriveBackendSyncTest, ConflictTest_DeleteFile_DeleteFile) { 1649 std::string app_id = "example"; 1650 1651 RegisterApp(app_id); 1652 1653 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL("")); 1654 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo"); 1655 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar"); 1656 1657 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1658 VerifyConsistency(); 1659 1660 // Test body starts from here. 1661 RemoveLocal(app_id, FPL("conflict_to_pending_remote")); 1662 RemoveLocal(app_id, FPL("conflict_to_existing_remote")); 1663 1664 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 1665 fake_drive_service_helper()->DeleteResource( 1666 GetFileIDByPath(app_id, FPL("conflict_to_pending_remote")))); 1667 1668 FetchRemoteChanges(); 1669 1670 EXPECT_EQ(google_apis::HTTP_NO_CONTENT, 1671 fake_drive_service_helper()->DeleteResource( 1672 GetFileIDByPath(app_id, FPL("conflict_to_existing_remote")))); 1673 1674 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone()); 1675 VerifyConsistency(); 1676 1677 EXPECT_EQ(1u, CountApp()); 1678 EXPECT_EQ(1u, CountLocalFile(app_id)); 1679 1680 EXPECT_EQ(2u, CountMetadata()); 1681 EXPECT_EQ(2u, CountTracker()); 1682} 1683 1684} // namespace drive_backend 1685} // namespace sync_file_system 1686