Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / sync_file_system / drive_backend / drive_backend_sync_unittest.cc
blobce49be98d63eb009c9005f132a6efaf63ab402ee
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.
5 #include <algorithm>
6 #include <stack>
8 #include "base/files/file_util.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h"
11 #include "base/thread_task_runner_handle.h"
12 #include "chrome/browser/drive/drive_uploader.h"
13 #include "chrome/browser/drive/fake_drive_service.h"
14 #include "chrome/browser/drive/test_util.h"
15 #include "chrome/browser/sync_file_system/drive_backend/callback_helper.h"
16 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants.h"
17 #include "chrome/browser/sync_file_system/drive_backend/fake_drive_service_helper.h"
18 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h"
19 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h"
20 #include "chrome/browser/sync_file_system/drive_backend/sync_engine.h"
21 #include "chrome/browser/sync_file_system/drive_backend/sync_engine_context.h"
22 #include "chrome/browser/sync_file_system/drive_backend/sync_worker.h"
23 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h"
24 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h"
25 #include "chrome/browser/sync_file_system/local/local_file_sync_service.h"
26 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
27 #include "chrome/browser/sync_file_system/sync_file_system_test_util.h"
28 #include "chrome/browser/sync_file_system/syncable_file_system_util.h"
29 #include "chrome/test/base/testing_profile.h"
30 #include "content/public/test/test_browser_thread.h"
31 #include "content/public/test/test_browser_thread_bundle.h"
32 #include "content/public/test/test_utils.h"
33 #include "extensions/common/extension.h"
34 #include "google_apis/drive/drive_api_parser.h"
35 #include "net/url_request/url_request_context_getter.h"
36 #include "storage/browser/fileapi/file_system_context.h"
37 #include "testing/gtest/include/gtest/gtest.h"
38 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h"
39 #include "third_party/leveldatabase/src/include/leveldb/env.h"
41 #define FPL(a) FILE_PATH_LITERAL(a)
43 namespace sync_file_system {
44 namespace drive_backend {
46 typedef storage::FileSystemOperation::FileEntryList FileEntryList;
48 namespace {
50 template <typename T>
51 void SetValueAndCallClosure(const base::Closure& closure,
52 T* arg_out,
53 T arg) {
54 *arg_out = base::internal::CallbackForward(arg);
55 closure.Run();
58 void SetSyncStatusAndUrl(const base::Closure& closure,
59 SyncStatusCode* status_out,
60 storage::FileSystemURL* url_out,
61 SyncStatusCode status,
62 const storage::FileSystemURL& url) {
63 *status_out = status;
64 *url_out = url;
65 closure.Run();
68 } // namespace
70 class DriveBackendSyncTest : public testing::Test,
71 public LocalFileSyncService::Observer,
72 public RemoteFileSyncService::Observer {
73 public:
74 DriveBackendSyncTest()
75 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
76 pending_remote_changes_(0),
77 pending_local_changes_(0) {}
78 ~DriveBackendSyncTest() override {}
80 void SetUp() override {
81 ASSERT_TRUE(base_dir_.CreateUniqueTempDir());
82 in_memory_env_.reset(leveldb::NewMemEnv(leveldb::Env::Default()));
84 io_task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread(
85 content::BrowserThread::IO);
86 scoped_refptr<base::SequencedWorkerPool> worker_pool(
87 content::BrowserThread::GetBlockingPool());
88 worker_task_runner_ =
89 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
90 worker_pool->GetSequenceToken(),
91 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
92 file_task_runner_ = content::BrowserThread::GetMessageLoopProxyForThread(
93 content::BrowserThread::FILE);
94 scoped_refptr<base::SequencedTaskRunner> drive_task_runner =
95 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
96 worker_pool->GetSequenceToken(),
97 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
99 RegisterSyncableFileSystem();
100 local_sync_service_ = LocalFileSyncService::CreateForTesting(
101 &profile_, in_memory_env_.get());
102 local_sync_service_->AddChangeObserver(this);
104 scoped_ptr<drive::FakeDriveService>
105 drive_service(new drive::FakeDriveService);
106 drive_service->Initialize("test@example.com");
107 ASSERT_TRUE(drive::test_util::SetUpTestEntries(drive_service.get()));
109 scoped_ptr<drive::DriveUploaderInterface> uploader(
110 new drive::DriveUploader(drive_service.get(),
111 file_task_runner_.get()));
113 fake_drive_service_helper_.reset(new FakeDriveServiceHelper(
114 drive_service.get(), uploader.get(),
115 kSyncRootFolderTitle));
117 remote_sync_service_.reset(
118 new SyncEngine(base::ThreadTaskRunnerHandle::Get(), // ui_task_runner
119 worker_task_runner_.get(),
120 drive_task_runner.get(),
121 worker_pool.get(),
122 base_dir_.path(),
123 nullptr, // task_logger
124 nullptr, // notification_manager
125 nullptr, // extension_service
126 nullptr, // signin_manager
127 nullptr, // token_service
128 nullptr, // request_context
129 nullptr, // drive_service
130 in_memory_env_.get()));
131 remote_sync_service_->AddServiceObserver(this);
132 remote_sync_service_->InitializeForTesting(
133 drive_service.Pass(), uploader.Pass(), nullptr /* sync_worker */);
134 remote_sync_service_->SetSyncEnabled(true);
136 local_sync_service_->SetLocalChangeProcessor(remote_sync_service_.get());
137 remote_sync_service_->SetRemoteChangeProcessor(local_sync_service_.get());
140 void TearDown() override {
141 typedef std::map<std::string, CannedSyncableFileSystem*>::iterator iterator;
142 for (iterator itr = file_systems_.begin();
143 itr != file_systems_.end(); ++itr) {
144 itr->second->TearDown();
145 delete itr->second;
147 file_systems_.clear();
149 local_sync_service_->Shutdown();
151 fake_drive_service_helper_.reset();
152 local_sync_service_.reset();
153 remote_sync_service_.reset();
155 content::RunAllBlockingPoolTasksUntilIdle();
156 RevokeSyncableFileSystem();
159 void OnRemoteChangeQueueUpdated(int64 pending_changes_hint) override {
160 pending_remote_changes_ = pending_changes_hint;
163 void OnLocalChangeAvailable(int64 pending_changes_hint) override {
164 pending_local_changes_ = pending_changes_hint;
167 protected:
168 storage::FileSystemURL CreateURL(const std::string& app_id,
169 const base::FilePath::StringType& path) {
170 return CreateURL(app_id, base::FilePath(path));
173 storage::FileSystemURL CreateURL(const std::string& app_id,
174 const base::FilePath& path) {
175 GURL origin = extensions::Extension::GetBaseURLFromExtensionId(app_id);
176 return CreateSyncableFileSystemURL(origin, path);
179 bool GetAppRootFolderID(const std::string& app_id,
180 std::string* folder_id) {
181 base::RunLoop run_loop;
182 bool success = false;
183 FileTracker tracker;
184 PostTaskAndReplyWithResult(
185 worker_task_runner_.get(),
186 FROM_HERE,
187 base::Bind(&MetadataDatabase::FindAppRootTracker,
188 base::Unretained(metadata_database()),
189 app_id,
190 &tracker),
191 base::Bind(
192 &SetValueAndCallClosure<bool>, run_loop.QuitClosure(), &success));
193 run_loop.Run();
194 if (!success)
195 return false;
196 *folder_id = tracker.file_id();
197 return true;
200 std::string GetFileIDByPath(const std::string& app_id,
201 const base::FilePath::StringType& path) {
202 return GetFileIDByPath(app_id, base::FilePath(path));
205 std::string GetFileIDByPath(const std::string& app_id,
206 const base::FilePath& path) {
207 base::RunLoop run_loop;
208 bool success = false;
209 FileTracker tracker;
210 base::FilePath result_path;
211 base::FilePath normalized_path = path.NormalizePathSeparators();
212 PostTaskAndReplyWithResult(
213 worker_task_runner_.get(),
214 FROM_HERE,
215 base::Bind(&MetadataDatabase::FindNearestActiveAncestor,
216 base::Unretained(metadata_database()),
217 app_id,
218 normalized_path,
219 &tracker,
220 &result_path),
221 base::Bind(
222 &SetValueAndCallClosure<bool>, run_loop.QuitClosure(), &success));
223 run_loop.Run();
224 EXPECT_TRUE(success);
225 EXPECT_EQ(normalized_path, result_path);
226 return tracker.file_id();
229 SyncStatusCode RegisterApp(const std::string& app_id) {
230 GURL origin = extensions::Extension::GetBaseURLFromExtensionId(app_id);
231 if (!ContainsKey(file_systems_, app_id)) {
232 CannedSyncableFileSystem* file_system = new CannedSyncableFileSystem(
233 origin, in_memory_env_.get(),
234 io_task_runner_.get(), file_task_runner_.get());
235 file_system->SetUp(CannedSyncableFileSystem::QUOTA_DISABLED);
237 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
238 base::RunLoop run_loop;
239 local_sync_service_->MaybeInitializeFileSystemContext(
240 origin, file_system->file_system_context(),
241 base::Bind(&SetValueAndCallClosure<SyncStatusCode>,
242 run_loop.QuitClosure(), &status));
243 run_loop.Run();
244 EXPECT_EQ(SYNC_STATUS_OK, status);
246 file_system->backend()->sync_context()->
247 set_mock_notify_changes_duration_in_sec(0);
249 EXPECT_EQ(base::File::FILE_OK, file_system->OpenFileSystem());
250 file_systems_[app_id] = file_system;
253 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
254 base::RunLoop run_loop;
255 remote_sync_service_->RegisterOrigin(
256 origin,
257 base::Bind(&SetValueAndCallClosure<SyncStatusCode>,
258 run_loop.QuitClosure(), &status));
259 run_loop.Run();
260 return status;
263 void AddLocalFolder(const std::string& app_id,
264 const base::FilePath::StringType& path) {
265 ASSERT_TRUE(ContainsKey(file_systems_, app_id));
266 EXPECT_EQ(base::File::FILE_OK,
267 file_systems_[app_id]->CreateDirectory(
268 CreateURL(app_id, path)));
271 void AddOrUpdateLocalFile(const std::string& app_id,
272 const base::FilePath::StringType& path,
273 const std::string& content) {
274 storage::FileSystemURL url(CreateURL(app_id, path));
275 ASSERT_TRUE(ContainsKey(file_systems_, app_id));
276 EXPECT_EQ(base::File::FILE_OK, file_systems_[app_id]->CreateFile(url));
277 int64 bytes_written = file_systems_[app_id]->WriteString(url, content);
278 EXPECT_EQ(static_cast<int64>(content.size()), bytes_written);
279 base::RunLoop().RunUntilIdle();
282 void UpdateLocalFile(const std::string& app_id,
283 const base::FilePath::StringType& path,
284 const std::string& content) {
285 ASSERT_TRUE(ContainsKey(file_systems_, app_id));
286 int64 bytes_written = file_systems_[app_id]->WriteString(
287 CreateURL(app_id, path), content);
288 EXPECT_EQ(static_cast<int64>(content.size()), bytes_written);
289 base::RunLoop().RunUntilIdle();
292 void RemoveLocal(const std::string& app_id,
293 const base::FilePath::StringType& path) {
294 ASSERT_TRUE(ContainsKey(file_systems_, app_id));
295 EXPECT_EQ(base::File::FILE_OK,
296 file_systems_[app_id]->Remove(
297 CreateURL(app_id, path),
298 true /* recursive */));
299 base::RunLoop().RunUntilIdle();
302 SyncStatusCode ProcessLocalChange() {
303 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
304 storage::FileSystemURL url;
305 base::RunLoop run_loop;
306 local_sync_service_->ProcessLocalChange(base::Bind(
307 &SetSyncStatusAndUrl, run_loop.QuitClosure(), &status, &url));
308 run_loop.Run();
309 return status;
312 SyncStatusCode ProcessRemoteChange() {
313 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
314 storage::FileSystemURL url;
315 base::RunLoop run_loop;
316 remote_sync_service_->ProcessRemoteChange(base::Bind(
317 &SetSyncStatusAndUrl, run_loop.QuitClosure(), &status, &url));
318 run_loop.Run();
319 return status;
322 int64 GetLargestChangeID() {
323 scoped_ptr<google_apis::AboutResource> about_resource;
324 EXPECT_EQ(google_apis::HTTP_SUCCESS,
325 fake_drive_service_helper()->GetAboutResource(&about_resource));
326 if (!about_resource)
327 return 0;
328 return about_resource->largest_change_id();
331 void FetchRemoteChanges() {
332 remote_sync_service_->OnNotificationReceived();
333 WaitForIdleWorker();
336 SyncStatusCode ProcessChangesUntilDone() {
337 int task_limit = 100;
338 SyncStatusCode local_sync_status;
339 SyncStatusCode remote_sync_status;
340 while (true) {
341 base::RunLoop().RunUntilIdle();
342 WaitForIdleWorker();
344 if (!task_limit--)
345 return SYNC_STATUS_ABORT;
347 local_sync_status = ProcessLocalChange();
348 if (local_sync_status != SYNC_STATUS_OK &&
349 local_sync_status != SYNC_STATUS_NO_CHANGE_TO_SYNC &&
350 local_sync_status != SYNC_STATUS_FILE_BUSY)
351 return local_sync_status;
353 remote_sync_status = ProcessRemoteChange();
354 if (remote_sync_status != SYNC_STATUS_OK &&
355 remote_sync_status != SYNC_STATUS_NO_CHANGE_TO_SYNC &&
356 remote_sync_status != SYNC_STATUS_FILE_BUSY)
357 return remote_sync_status;
359 if (local_sync_status == SYNC_STATUS_NO_CHANGE_TO_SYNC &&
360 remote_sync_status == SYNC_STATUS_NO_CHANGE_TO_SYNC) {
362 base::RunLoop run_loop;
363 remote_sync_service_->PromoteDemotedChanges(run_loop.QuitClosure());
364 run_loop.Run();
368 base::RunLoop run_loop;
369 local_sync_service_->PromoteDemotedChanges(run_loop.QuitClosure());
370 run_loop.Run();
373 if (pending_remote_changes_ || pending_local_changes_)
374 continue;
376 base::RunLoop run_loop;
377 int64 largest_fetched_change_id = -1;
378 PostTaskAndReplyWithResult(
379 worker_task_runner_.get(),
380 FROM_HERE,
381 base::Bind(&MetadataDatabase::GetLargestFetchedChangeID,
382 base::Unretained(metadata_database())),
383 base::Bind(&SetValueAndCallClosure<int64>,
384 run_loop.QuitClosure(),
385 &largest_fetched_change_id));
386 run_loop.Run();
387 if (largest_fetched_change_id != GetLargestChangeID()) {
388 FetchRemoteChanges();
389 continue;
391 break;
394 return SYNC_STATUS_OK;
397 // Verifies local and remote files/folders are consistent.
398 // This function checks:
399 // - Each registered origin has corresponding remote folder.
400 // - Each local file/folder has corresponding remote one.
401 // - Each remote file/folder has corresponding local one.
402 // TODO(tzik): Handle conflict case. i.e. allow remote file has different
403 // file content if the corresponding local file conflicts to it.
404 void VerifyConsistency() {
405 std::string sync_root_folder_id;
406 google_apis::DriveApiErrorCode error =
407 fake_drive_service_helper_->GetSyncRootFolderID(&sync_root_folder_id);
408 if (sync_root_folder_id.empty()) {
409 EXPECT_EQ(google_apis::HTTP_NOT_FOUND, error);
410 EXPECT_TRUE(file_systems_.empty());
411 return;
413 EXPECT_EQ(google_apis::HTTP_SUCCESS, error);
415 ScopedVector<google_apis::FileResource> remote_entries;
416 EXPECT_EQ(google_apis::HTTP_SUCCESS,
417 fake_drive_service_helper_->ListFilesInFolder(
418 sync_root_folder_id, &remote_entries));
419 std::map<std::string, const google_apis::FileResource*> app_root_by_title;
420 for (ScopedVector<google_apis::FileResource>::iterator itr =
421 remote_entries.begin();
422 itr != remote_entries.end();
423 ++itr) {
424 const google_apis::FileResource& remote_entry = **itr;
425 EXPECT_FALSE(ContainsKey(app_root_by_title, remote_entry.title()));
426 app_root_by_title[remote_entry.title()] = *itr;
429 for (std::map<std::string, CannedSyncableFileSystem*>::const_iterator itr =
430 file_systems_.begin();
431 itr != file_systems_.end(); ++itr) {
432 const std::string& app_id = itr->first;
433 SCOPED_TRACE(testing::Message() << "Verifying app: " << app_id);
434 CannedSyncableFileSystem* file_system = itr->second;
435 ASSERT_TRUE(ContainsKey(app_root_by_title, app_id));
436 VerifyConsistencyForFolder(
437 app_id, base::FilePath(),
438 app_root_by_title[app_id]->file_id(),
439 file_system);
443 void VerifyConsistencyForFolder(const std::string& app_id,
444 const base::FilePath& path,
445 const std::string& folder_id,
446 CannedSyncableFileSystem* file_system) {
447 SCOPED_TRACE(testing::Message() << "Verifying folder: " << path.value());
449 ScopedVector<google_apis::FileResource> remote_entries;
450 EXPECT_EQ(google_apis::HTTP_SUCCESS,
451 fake_drive_service_helper_->ListFilesInFolder(
452 folder_id, &remote_entries));
453 std::map<std::string, const google_apis::FileResource*>
454 remote_entry_by_title;
455 for (size_t i = 0; i < remote_entries.size(); ++i) {
456 google_apis::FileResource* remote_entry = remote_entries[i];
457 EXPECT_FALSE(ContainsKey(remote_entry_by_title, remote_entry->title()))
458 << "title: " << remote_entry->title();
459 remote_entry_by_title[remote_entry->title()] = remote_entry;
462 storage::FileSystemURL url(CreateURL(app_id, path));
463 FileEntryList local_entries;
464 EXPECT_EQ(base::File::FILE_OK,
465 file_system->ReadDirectory(url, &local_entries));
466 for (FileEntryList::iterator itr = local_entries.begin();
467 itr != local_entries.end();
468 ++itr) {
469 const storage::DirectoryEntry& local_entry = *itr;
470 storage::FileSystemURL entry_url(
471 CreateURL(app_id, path.Append(local_entry.name)));
472 std::string title =
473 storage::VirtualPath::BaseName(entry_url.path()).AsUTF8Unsafe();
474 SCOPED_TRACE(testing::Message() << "Verifying entry: " << title);
476 ASSERT_TRUE(ContainsKey(remote_entry_by_title, title));
477 const google_apis::FileResource& remote_entry =
478 *remote_entry_by_title[title];
479 if (local_entry.is_directory) {
480 ASSERT_TRUE(remote_entry.IsDirectory());
481 VerifyConsistencyForFolder(app_id, entry_url.path(),
482 remote_entry.file_id(),
483 file_system);
484 } else {
485 ASSERT_FALSE(remote_entry.IsDirectory());
486 VerifyConsistencyForFile(app_id, entry_url.path(),
487 remote_entry.file_id(),
488 file_system);
490 remote_entry_by_title.erase(title);
493 EXPECT_TRUE(remote_entry_by_title.empty());
496 void VerifyConsistencyForFile(const std::string& app_id,
497 const base::FilePath& path,
498 const std::string& file_id,
499 CannedSyncableFileSystem* file_system) {
500 storage::FileSystemURL url(CreateURL(app_id, path));
501 std::string file_content;
502 EXPECT_EQ(google_apis::HTTP_SUCCESS,
503 fake_drive_service_helper_->ReadFile(file_id, &file_content));
504 EXPECT_EQ(base::File::FILE_OK,
505 file_system->VerifyFile(url, file_content));
508 size_t CountApp() {
509 return file_systems_.size();
512 size_t CountLocalFile(const std::string& app_id) {
513 if (!ContainsKey(file_systems_, app_id))
514 return 0;
516 CannedSyncableFileSystem* file_system = file_systems_[app_id];
517 std::stack<base::FilePath> folders;
518 folders.push(base::FilePath()); // root folder
520 size_t result = 1;
521 while (!folders.empty()) {
522 storage::FileSystemURL url(CreateURL(app_id, folders.top()));
523 folders.pop();
525 FileEntryList entries;
526 EXPECT_EQ(base::File::FILE_OK,
527 file_system->ReadDirectory(url, &entries));
528 for (FileEntryList::iterator itr = entries.begin();
529 itr != entries.end(); ++itr) {
530 ++result;
531 if (itr->is_directory)
532 folders.push(url.path().Append(itr->name));
536 return result;
539 void VerifyLocalFile(const std::string& app_id,
540 const base::FilePath::StringType& path,
541 const std::string& content) {
542 SCOPED_TRACE(testing::Message() << "Verifying local file: "
543 << "app_id = " << app_id
544 << ", path = " << path);
545 ASSERT_TRUE(ContainsKey(file_systems_, app_id));
546 EXPECT_EQ(base::File::FILE_OK,
547 file_systems_[app_id]->VerifyFile(
548 CreateURL(app_id, path), content));
551 void VerifyLocalFolder(const std::string& app_id,
552 const base::FilePath::StringType& path) {
553 SCOPED_TRACE(testing::Message() << "Verifying local file: "
554 << "app_id = " << app_id
555 << ", path = " << path);
556 ASSERT_TRUE(ContainsKey(file_systems_, app_id));
557 EXPECT_EQ(base::File::FILE_OK,
558 file_systems_[app_id]->DirectoryExists(CreateURL(app_id, path)));
561 size_t CountMetadata() {
562 size_t count = 0;
563 base::RunLoop run_loop;
564 PostTaskAndReplyWithResult(
565 worker_task_runner_.get(),
566 FROM_HERE,
567 base::Bind(&MetadataDatabase::CountFileMetadata,
568 base::Unretained(metadata_database())),
569 base::Bind(
570 &SetValueAndCallClosure<size_t>, run_loop.QuitClosure(), &count));
571 run_loop.Run();
572 return count;
575 size_t CountTracker() {
576 size_t count = 0;
577 base::RunLoop run_loop;
578 PostTaskAndReplyWithResult(
579 worker_task_runner_.get(),
580 FROM_HERE,
581 base::Bind(&MetadataDatabase::CountFileTracker,
582 base::Unretained(metadata_database())),
583 base::Bind(
584 &SetValueAndCallClosure<size_t>, run_loop.QuitClosure(), &count));
585 run_loop.Run();
586 return count;
589 drive::FakeDriveService* fake_drive_service() {
590 return static_cast<drive::FakeDriveService*>(
591 remote_sync_service_->drive_service_.get());
594 FakeDriveServiceHelper* fake_drive_service_helper() {
595 return fake_drive_service_helper_.get();
598 void WaitForIdleWorker() {
599 base::RunLoop run_loop;
600 worker_task_runner_->PostTask(
601 FROM_HERE,
602 base::Bind(&SyncWorker::CallOnIdleForTesting,
603 base::Unretained(sync_worker()),
604 RelayCallbackToCurrentThread(
605 FROM_HERE,
606 run_loop.QuitClosure())));
607 run_loop.Run();
610 private:
611 SyncWorker* sync_worker() {
612 return static_cast<SyncWorker*>(remote_sync_service_->sync_worker_.get());
615 // MetadataDatabase is normally used on the worker thread.
616 // Use this only when there is no task running on the worker.
617 MetadataDatabase* metadata_database() {
618 return sync_worker()->context_->metadata_database_.get();
621 content::TestBrowserThreadBundle thread_bundle_;
623 base::ScopedTempDir base_dir_;
624 scoped_ptr<leveldb::Env> in_memory_env_;
625 TestingProfile profile_;
627 scoped_ptr<SyncEngine> remote_sync_service_;
628 scoped_ptr<LocalFileSyncService> local_sync_service_;
630 int64 pending_remote_changes_;
631 int64 pending_local_changes_;
633 scoped_ptr<FakeDriveServiceHelper> fake_drive_service_helper_;
634 std::map<std::string, CannedSyncableFileSystem*> file_systems_;
637 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
638 scoped_refptr<base::SequencedTaskRunner> worker_task_runner_;
639 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
641 DISALLOW_COPY_AND_ASSIGN(DriveBackendSyncTest);
644 TEST_F(DriveBackendSyncTest, LocalToRemoteBasicTest) {
645 std::string app_id = "example";
647 RegisterApp(app_id);
648 AddOrUpdateLocalFile(app_id, FPL("file"), "abcde");
650 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
651 VerifyConsistency();
653 EXPECT_EQ(1u, CountApp());
654 EXPECT_EQ(2u, CountLocalFile(app_id));
655 VerifyLocalFile(app_id, FPL("file"), "abcde");
657 EXPECT_EQ(3u, CountMetadata());
658 EXPECT_EQ(3u, CountTracker());
661 TEST_F(DriveBackendSyncTest, RemoteToLocalBasicTest) {
662 std::string app_id = "example";
663 RegisterApp(app_id);
665 std::string app_root_folder_id;
666 EXPECT_TRUE(GetAppRootFolderID(app_id, &app_root_folder_id));
668 std::string file_id;
669 EXPECT_EQ(google_apis::HTTP_SUCCESS,
670 fake_drive_service_helper()->AddFile(
671 app_root_folder_id, "file", "abcde", &file_id));
673 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
674 VerifyConsistency();
676 EXPECT_EQ(1u, CountApp());
677 EXPECT_EQ(2u, CountLocalFile(app_id));
678 VerifyLocalFile(app_id, FPL("file"), "abcde");
680 EXPECT_EQ(3u, CountMetadata());
681 EXPECT_EQ(3u, CountTracker());
684 TEST_F(DriveBackendSyncTest, LocalFileUpdateTest) {
685 std::string app_id = "example";
686 const base::FilePath::StringType kPath(FPL("file"));
688 RegisterApp(app_id);
689 AddOrUpdateLocalFile(app_id, kPath, "abcde");
691 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
692 VerifyConsistency();
694 UpdateLocalFile(app_id, kPath, "1234567890");
696 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
697 VerifyConsistency();
699 EXPECT_EQ(1u, CountApp());
700 EXPECT_EQ(2u, CountLocalFile(app_id));
701 VerifyLocalFile(app_id, FPL("file"), "1234567890");
703 EXPECT_EQ(3u, CountMetadata());
704 EXPECT_EQ(3u, CountTracker());
707 TEST_F(DriveBackendSyncTest, RemoteFileUpdateTest) {
708 std::string app_id = "example";
710 RegisterApp(app_id);
711 std::string remote_file_id;
712 std::string app_root_folder_id;
713 EXPECT_TRUE(GetAppRootFolderID(app_id, &app_root_folder_id));
714 EXPECT_EQ(google_apis::HTTP_SUCCESS,
715 fake_drive_service_helper()->AddFile(
716 app_root_folder_id, "file", "abcde", &remote_file_id));
718 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
719 VerifyConsistency();
721 EXPECT_EQ(google_apis::HTTP_SUCCESS,
722 fake_drive_service_helper()->UpdateFile(
723 remote_file_id, "1234567890"));
725 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
726 VerifyConsistency();
728 EXPECT_EQ(1u, CountApp());
729 EXPECT_EQ(2u, CountLocalFile(app_id));
730 VerifyLocalFile(app_id, FPL("file"), "1234567890");
732 EXPECT_EQ(3u, CountMetadata());
733 EXPECT_EQ(3u, CountTracker());
736 TEST_F(DriveBackendSyncTest, LocalFileDeletionTest) {
737 std::string app_id = "example";
738 const base::FilePath::StringType path(FPL("file"));
740 RegisterApp(app_id);
741 AddOrUpdateLocalFile(app_id, path, "abcde");
743 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
744 VerifyConsistency();
746 RemoveLocal(app_id, path);
748 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
749 VerifyConsistency();
751 EXPECT_EQ(1u, CountApp());
752 EXPECT_EQ(1u, CountLocalFile(app_id));
754 EXPECT_EQ(2u, CountMetadata());
755 EXPECT_EQ(2u, CountTracker());
758 TEST_F(DriveBackendSyncTest, RemoteFileDeletionTest) {
759 std::string app_id = "example";
760 const base::FilePath::StringType path(FPL("file"));
762 RegisterApp(app_id);
763 AddOrUpdateLocalFile(app_id, path, "abcde");
765 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
766 VerifyConsistency();
768 std::string file_id = GetFileIDByPath(app_id, path);
769 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
770 fake_drive_service_helper()->DeleteResource(file_id));
772 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
773 VerifyConsistency();
775 EXPECT_EQ(1u, CountApp());
776 EXPECT_EQ(1u, CountLocalFile(app_id));
778 EXPECT_EQ(2u, CountMetadata());
779 EXPECT_EQ(2u, CountTracker());
782 TEST_F(DriveBackendSyncTest, RemoteRenameTest) {
783 std::string app_id = "example";
784 const base::FilePath::StringType path(FPL("file"));
786 RegisterApp(app_id);
787 AddOrUpdateLocalFile(app_id, path, "abcde");
789 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
790 VerifyConsistency();
792 std::string file_id = GetFileIDByPath(app_id, path);
793 EXPECT_EQ(google_apis::HTTP_SUCCESS,
794 fake_drive_service_helper()->RenameResource(
795 file_id, "renamed_file"));
797 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
798 VerifyConsistency();
800 EXPECT_EQ(1u, CountApp());
801 EXPECT_EQ(2u, CountLocalFile(app_id));
802 VerifyLocalFile(app_id, FPL("renamed_file"), "abcde");
804 EXPECT_EQ(3u, CountMetadata());
805 EXPECT_EQ(3u, CountTracker());
808 TEST_F(DriveBackendSyncTest, RemoteRenameAndRevertTest) {
809 std::string app_id = "example";
810 const base::FilePath::StringType path(FPL("file"));
812 RegisterApp(app_id);
813 AddOrUpdateLocalFile(app_id, path, "abcde");
815 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
816 VerifyConsistency();
818 std::string file_id = GetFileIDByPath(app_id, path);
819 EXPECT_EQ(google_apis::HTTP_SUCCESS,
820 fake_drive_service_helper()->RenameResource(
821 file_id, "renamed_file"));
823 FetchRemoteChanges();
825 EXPECT_EQ(google_apis::HTTP_SUCCESS,
826 fake_drive_service_helper()->RenameResource(
827 file_id, base::FilePath(path).AsUTF8Unsafe()));
829 FetchRemoteChanges();
831 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
832 VerifyConsistency();
834 EXPECT_EQ(1u, CountApp());
835 EXPECT_EQ(2u, CountLocalFile(app_id));
836 VerifyLocalFile(app_id, FPL("file"), "abcde");
838 EXPECT_EQ(3u, CountMetadata());
839 EXPECT_EQ(3u, CountTracker());
842 TEST_F(DriveBackendSyncTest, ReorganizeToOtherFolder) {
843 std::string app_id = "example";
844 const base::FilePath::StringType path(FPL("file"));
846 RegisterApp(app_id);
847 AddLocalFolder(app_id, FPL("folder_src"));
848 AddLocalFolder(app_id, FPL("folder_dest"));
849 AddOrUpdateLocalFile(app_id, FPL("folder_src/file"), "abcde");
851 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
852 VerifyConsistency();
854 std::string file_id = GetFileIDByPath(app_id, FPL("folder_src/file"));
855 std::string src_folder_id = GetFileIDByPath(app_id, FPL("folder_src"));
856 std::string dest_folder_id = GetFileIDByPath(app_id, FPL("folder_dest"));
857 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
858 fake_drive_service_helper()->RemoveResourceFromDirectory(
859 src_folder_id, file_id));
860 EXPECT_EQ(google_apis::HTTP_SUCCESS,
861 fake_drive_service_helper()->AddResourceToDirectory(
862 dest_folder_id, file_id));
864 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
865 VerifyConsistency();
867 EXPECT_EQ(1u, CountApp());
868 EXPECT_EQ(4u, CountLocalFile(app_id));
869 VerifyLocalFolder(app_id, FPL("folder_dest"));
870 VerifyLocalFile(app_id, FPL("folder_dest/file"), "abcde");
872 EXPECT_EQ(5u, CountMetadata());
873 EXPECT_EQ(5u, CountTracker());
876 TEST_F(DriveBackendSyncTest, ReorganizeToOtherApp) {
877 std::string src_app_id = "src_app";
878 std::string dest_app_id = "dest_app";
880 RegisterApp(src_app_id);
881 RegisterApp(dest_app_id);
883 AddLocalFolder(src_app_id, FPL("folder_src"));
884 AddLocalFolder(dest_app_id, FPL("folder_dest"));
885 AddOrUpdateLocalFile(src_app_id, FPL("folder_src/file"), "abcde");
887 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
888 VerifyConsistency();
890 std::string file_id = GetFileIDByPath(src_app_id, FPL("folder_src/file"));
891 std::string src_folder_id = GetFileIDByPath(src_app_id, FPL("folder_src"));
892 std::string dest_folder_id = GetFileIDByPath(dest_app_id, FPL("folder_dest"));
893 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
894 fake_drive_service_helper()->RemoveResourceFromDirectory(
895 src_folder_id, file_id));
896 EXPECT_EQ(google_apis::HTTP_SUCCESS,
897 fake_drive_service_helper()->AddResourceToDirectory(
898 dest_folder_id, file_id));
900 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
901 VerifyConsistency();
903 EXPECT_EQ(2u, CountApp());
904 EXPECT_EQ(2u, CountLocalFile(src_app_id));
905 EXPECT_EQ(3u, CountLocalFile(dest_app_id));
906 VerifyLocalFile(dest_app_id, FPL("folder_dest/file"), "abcde");
908 EXPECT_EQ(6u, CountMetadata());
909 EXPECT_EQ(6u, CountTracker());
912 TEST_F(DriveBackendSyncTest, ReorganizeToUnmanagedArea) {
913 std::string app_id = "example";
915 RegisterApp(app_id);
917 AddLocalFolder(app_id, FPL("folder_src"));
918 AddOrUpdateLocalFile(app_id, FPL("folder_src/file_orphaned"), "abcde");
919 AddOrUpdateLocalFile(app_id, FPL("folder_src/file_under_sync_root"), "123");
920 AddOrUpdateLocalFile(app_id, FPL("folder_src/file_under_drive_root"), "hoge");
922 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
923 VerifyConsistency();
925 std::string file_orphaned_id =
926 GetFileIDByPath(app_id, FPL("folder_src/file_orphaned"));
927 std::string file_under_sync_root_id =
928 GetFileIDByPath(app_id, FPL("folder_src/file_under_sync_root"));
929 std::string file_under_drive_root_id =
930 GetFileIDByPath(app_id, FPL("folder_src/file_under_drive_root"));
932 std::string folder_id = GetFileIDByPath(app_id, FPL("folder_src"));
933 std::string sync_root_folder_id;
934 EXPECT_EQ(google_apis::HTTP_SUCCESS,
935 fake_drive_service_helper()->GetSyncRootFolderID(
936 &sync_root_folder_id));
938 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
939 fake_drive_service_helper()->RemoveResourceFromDirectory(
940 folder_id, file_orphaned_id));
941 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
942 fake_drive_service_helper()->RemoveResourceFromDirectory(
943 folder_id, file_under_sync_root_id));
944 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
945 fake_drive_service_helper()->RemoveResourceFromDirectory(
946 folder_id, file_under_drive_root_id));
948 EXPECT_EQ(google_apis::HTTP_SUCCESS,
949 fake_drive_service_helper()->AddResourceToDirectory(
950 sync_root_folder_id, file_under_sync_root_id));
951 EXPECT_EQ(google_apis::HTTP_SUCCESS,
952 fake_drive_service_helper()->AddResourceToDirectory(
953 fake_drive_service()->GetRootResourceId(),
954 file_under_drive_root_id));
956 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
957 VerifyConsistency();
959 EXPECT_EQ(1u, CountApp());
960 EXPECT_EQ(2u, CountLocalFile(app_id));
962 EXPECT_EQ(4u, CountMetadata());
963 EXPECT_EQ(4u, CountTracker());
966 TEST_F(DriveBackendSyncTest, ReorganizeToMultipleParents) {
967 std::string app_id = "example";
969 RegisterApp(app_id);
971 AddLocalFolder(app_id, FPL("parent1"));
972 AddLocalFolder(app_id, FPL("parent2"));
973 AddOrUpdateLocalFile(app_id, FPL("parent1/file"), "abcde");
975 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
976 VerifyConsistency();
978 std::string file_id = GetFileIDByPath(app_id, FPL("parent1/file"));
979 std::string parent2_folder_id = GetFileIDByPath(app_id, FPL("parent2"));
980 EXPECT_EQ(google_apis::HTTP_SUCCESS,
981 fake_drive_service_helper()->AddResourceToDirectory(
982 parent2_folder_id, file_id));
984 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
985 VerifyConsistency();
987 EXPECT_EQ(1u, CountApp());
988 EXPECT_EQ(4u, CountLocalFile(app_id));
989 VerifyLocalFolder(app_id, FPL("parent1"));
990 VerifyLocalFolder(app_id, FPL("parent2"));
991 VerifyLocalFile(app_id, FPL("parent1/file"), "abcde");
993 EXPECT_EQ(5u, CountMetadata());
994 EXPECT_EQ(5u, CountTracker());
997 TEST_F(DriveBackendSyncTest, ReorganizeAndRevert) {
998 std::string app_id = "example";
1000 RegisterApp(app_id);
1002 AddLocalFolder(app_id, FPL("folder"));
1003 AddLocalFolder(app_id, FPL("folder_temp"));
1004 AddOrUpdateLocalFile(app_id, FPL("folder/file"), "abcde");
1006 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1007 VerifyConsistency();
1009 std::string file_id = GetFileIDByPath(app_id, FPL("folder/file"));
1010 std::string folder_id = GetFileIDByPath(app_id, FPL("folder"));
1011 std::string folder_temp_id = GetFileIDByPath(app_id, FPL("folder_temp"));
1012 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
1013 fake_drive_service_helper()->RemoveResourceFromDirectory(
1014 folder_id, file_id));
1015 EXPECT_EQ(google_apis::HTTP_SUCCESS,
1016 fake_drive_service_helper()->AddResourceToDirectory(
1017 folder_temp_id, file_id));
1019 FetchRemoteChanges();
1021 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
1022 fake_drive_service_helper()->RemoveResourceFromDirectory(
1023 folder_temp_id, file_id));
1024 EXPECT_EQ(google_apis::HTTP_SUCCESS,
1025 fake_drive_service_helper()->AddResourceToDirectory(
1026 folder_id, file_id));
1028 FetchRemoteChanges();
1030 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1031 VerifyConsistency();
1033 EXPECT_EQ(1u, CountApp());
1034 EXPECT_EQ(4u, CountLocalFile(app_id));
1035 VerifyLocalFolder(app_id, FPL("folder"));
1036 VerifyLocalFile(app_id, FPL("folder/file"), "abcde");
1038 EXPECT_EQ(5u, CountMetadata());
1039 EXPECT_EQ(5u, CountTracker());
1042 TEST_F(DriveBackendSyncTest, ConflictTest_ConflictTest_AddFolder_AddFolder) {
1043 std::string app_id = "example";
1045 RegisterApp(app_id);
1046 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL(""));
1048 AddLocalFolder(app_id, FPL("conflict_to_pending_remote"));
1049 AddLocalFolder(app_id, FPL("conflict_to_existing_remote"));
1051 std::string remote_folder_id;
1052 EXPECT_EQ(google_apis::HTTP_CREATED,
1053 fake_drive_service_helper()->AddFolder(
1054 app_root_folder_id,
1055 "conflict_to_pending_remote", &remote_folder_id));
1057 FetchRemoteChanges();
1059 EXPECT_EQ(google_apis::HTTP_CREATED,
1060 fake_drive_service_helper()->AddFolder(
1061 app_root_folder_id,
1062 "conflict_to_existing_remote", &remote_folder_id));
1064 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1065 VerifyConsistency();
1067 EXPECT_EQ(1u, CountApp());
1068 EXPECT_EQ(3u, CountLocalFile(app_id));
1069 VerifyLocalFolder(app_id, FPL("conflict_to_pending_remote"));
1070 VerifyLocalFolder(app_id, FPL("conflict_to_existing_remote"));
1072 EXPECT_EQ(4u, CountMetadata());
1073 EXPECT_EQ(4u, CountTracker());
1076 TEST_F(DriveBackendSyncTest, ConflictTest_AddFolder_DeleteFolder) {
1077 std::string app_id = "example";
1079 RegisterApp(app_id);
1081 AddLocalFolder(app_id, FPL("conflict_to_pending_remote"));
1082 AddLocalFolder(app_id, FPL("conflict_to_existing_remote"));
1084 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1085 VerifyConsistency();
1087 // Test body starts from here.
1088 RemoveLocal(app_id, FPL("conflict_to_pending_remote"));
1089 AddLocalFolder(app_id, FPL("conflict_to_pending_remote"));
1090 RemoveLocal(app_id, FPL("conflict_to_existing_remote"));
1091 AddLocalFolder(app_id, FPL("conflict_to_existing_remote"));
1093 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
1094 fake_drive_service_helper()->DeleteResource(
1095 GetFileIDByPath(app_id, FPL("conflict_to_pending_remote"))));
1097 FetchRemoteChanges();
1099 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
1100 fake_drive_service_helper()->DeleteResource(
1101 GetFileIDByPath(app_id, FPL("conflict_to_existing_remote"))));
1103 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1104 VerifyConsistency();
1106 EXPECT_EQ(1u, CountApp());
1107 EXPECT_EQ(2u, CountLocalFile(app_id));
1108 VerifyLocalFolder(app_id, FPL("conflict_to_pending_remote"));
1110 EXPECT_EQ(3u, CountMetadata());
1111 EXPECT_EQ(3u, CountTracker());
1114 TEST_F(DriveBackendSyncTest, ConflictTest_AddFolder_AddFile) {
1115 std::string app_id = "example";
1117 RegisterApp(app_id);
1118 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL(""));
1120 AddLocalFolder(app_id, FPL("conflict_to_pending_remote"));
1121 AddLocalFolder(app_id, FPL("conflict_to_existing_remote"));
1123 std::string file_id;
1124 EXPECT_EQ(google_apis::HTTP_SUCCESS,
1125 fake_drive_service_helper()->AddFile(
1126 app_root_folder_id, "conflict_to_pending_remote", "foo",
1127 &file_id));
1128 EXPECT_EQ(google_apis::HTTP_SUCCESS,
1129 fake_drive_service_helper()->UpdateModificationTime(
1130 file_id,
1131 base::Time::Now() + base::TimeDelta::FromDays(1)));
1133 FetchRemoteChanges();
1135 EXPECT_EQ(google_apis::HTTP_SUCCESS,
1136 fake_drive_service_helper()->AddFile(
1137 app_root_folder_id, "conflict_to_existing_remote", "foo",
1138 &file_id));
1139 EXPECT_EQ(google_apis::HTTP_SUCCESS,
1140 fake_drive_service_helper()->UpdateModificationTime(
1141 file_id,
1142 base::Time::Now() + base::TimeDelta::FromDays(1)));
1144 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1145 VerifyConsistency();
1147 EXPECT_EQ(1u, CountApp());
1148 EXPECT_EQ(3u, CountLocalFile(app_id));
1149 VerifyLocalFolder(app_id, FPL("conflict_to_pending_remote"));
1150 VerifyLocalFolder(app_id, FPL("conflict_to_existing_remote"));
1152 EXPECT_EQ(4u, CountMetadata());
1153 EXPECT_EQ(4u, CountTracker());
1156 TEST_F(DriveBackendSyncTest, ConflictTest_AddFolder_DeleteFile) {
1157 std::string app_id = "example";
1159 RegisterApp(app_id);
1160 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL(""));
1162 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo");
1163 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar");
1165 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1166 VerifyConsistency();
1168 // Test body starts from here.
1169 RemoveLocal(app_id, FPL("conflict_to_pending_remote"));
1170 AddLocalFolder(app_id, FPL("conflict_to_pending_remote"));
1172 RemoveLocal(app_id, FPL("conflict_to_existing_remote"));
1173 AddLocalFolder(app_id, FPL("conflict_to_existing_remote"));
1175 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
1176 fake_drive_service_helper()->DeleteResource(
1177 GetFileIDByPath(app_id, FPL("conflict_to_pending_remote"))));
1179 FetchRemoteChanges();
1181 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
1182 fake_drive_service_helper()->DeleteResource(
1183 GetFileIDByPath(app_id, FPL("conflict_to_existing_remote"))));
1185 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1186 VerifyConsistency();
1188 EXPECT_EQ(1u, CountApp());
1189 EXPECT_EQ(3u, CountLocalFile(app_id));
1190 VerifyLocalFolder(app_id, FPL("conflict_to_pending_remote"));
1191 VerifyLocalFolder(app_id, FPL("conflict_to_existing_remote"));
1193 EXPECT_EQ(4u, CountMetadata());
1194 EXPECT_EQ(4u, CountTracker());
1197 TEST_F(DriveBackendSyncTest, ConflictTest_DeleteFolder_AddFolder) {
1198 std::string app_id = "example";
1200 RegisterApp(app_id);
1201 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL(""));
1202 AddLocalFolder(app_id, FPL("conflict_to_pending_remote"));
1203 AddLocalFolder(app_id, FPL("conflict_to_existing_remote"));
1205 RemoveLocal(app_id, FPL("conflict_to_pending_remote"));
1206 RemoveLocal(app_id, FPL("conflict_to_existing_remote"));
1208 std::string file_id;
1209 EXPECT_EQ(google_apis::HTTP_CREATED,
1210 fake_drive_service_helper()->AddFolder(
1211 app_root_folder_id,
1212 "conflict_to_pending_remote", &file_id));
1214 FetchRemoteChanges();
1216 EXPECT_EQ(google_apis::HTTP_CREATED,
1217 fake_drive_service_helper()->AddFolder(
1218 app_root_folder_id,
1219 "conflict_to_existing_remote", nullptr));
1221 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1222 VerifyConsistency();
1224 EXPECT_EQ(1u, CountApp());
1225 EXPECT_EQ(3u, CountLocalFile(app_id));
1226 VerifyLocalFolder(app_id, FPL("conflict_to_pending_remote"));
1227 VerifyLocalFolder(app_id, FPL("conflict_to_existing_remote"));
1229 EXPECT_EQ(4u, CountMetadata());
1230 EXPECT_EQ(4u, CountTracker());
1233 TEST_F(DriveBackendSyncTest, ConflictTest_DeleteFolder_DeleteFolder) {
1234 std::string app_id = "example";
1236 RegisterApp(app_id);
1237 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL(""));
1239 AddLocalFolder(app_id, FPL("conflict_to_pending_remote"));
1240 AddLocalFolder(app_id, FPL("conflict_to_existing_remote"));
1242 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1243 VerifyConsistency();
1245 // Test body starts from here.
1246 RemoveLocal(app_id, FPL("conflict_to_pending_remote"));
1247 RemoveLocal(app_id, FPL("conflict_to_existing_remote"));
1249 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
1250 fake_drive_service_helper()->DeleteResource(
1251 GetFileIDByPath(app_id, FPL("conflict_to_pending_remote"))));
1253 FetchRemoteChanges();
1255 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
1256 fake_drive_service_helper()->DeleteResource(
1257 GetFileIDByPath(app_id, FPL("conflict_to_existing_remote"))));
1259 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1260 VerifyConsistency();
1262 EXPECT_EQ(1u, CountApp());
1263 EXPECT_EQ(1u, CountLocalFile(app_id));
1265 EXPECT_EQ(2u, CountMetadata());
1266 EXPECT_EQ(2u, CountTracker());
1269 TEST_F(DriveBackendSyncTest, ConflictTest_DeleteFolder_AddFile) {
1270 std::string app_id = "example";
1272 RegisterApp(app_id);
1273 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL(""));
1275 AddLocalFolder(app_id, FPL("conflict_to_pending_remote"));
1276 AddLocalFolder(app_id, FPL("conflict_to_existing_remote"));
1277 RemoveLocal(app_id, FPL("conflict_to_pending_remote"));
1278 RemoveLocal(app_id, FPL("conflict_to_existing_remote"));
1280 EXPECT_EQ(google_apis::HTTP_SUCCESS,
1281 fake_drive_service_helper()->AddFile(
1282 app_root_folder_id, "conflict_to_pending_remote", "foo",
1283 nullptr));
1285 FetchRemoteChanges();
1287 EXPECT_EQ(google_apis::HTTP_SUCCESS,
1288 fake_drive_service_helper()->AddFile(
1289 app_root_folder_id, "conflict_to_existing_remote", "bar",
1290 nullptr));
1292 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1293 VerifyConsistency();
1295 EXPECT_EQ(1u, CountApp());
1296 EXPECT_EQ(3u, CountLocalFile(app_id));
1297 VerifyLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo");
1298 VerifyLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar");
1300 EXPECT_EQ(4u, CountMetadata());
1301 EXPECT_EQ(4u, CountTracker());
1304 TEST_F(DriveBackendSyncTest, ConflictTest_DeleteFolder_DeleteFile) {
1305 std::string app_id = "example";
1307 RegisterApp(app_id);
1308 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL(""));
1309 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo");
1310 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar");
1312 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1313 VerifyConsistency();
1315 // Test body starts from here.
1316 RemoveLocal(app_id, FPL("conflict_to_pending_remote"));
1317 RemoveLocal(app_id, FPL("conflict_to_existing_remote"));
1319 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
1320 fake_drive_service_helper()->DeleteResource(
1321 GetFileIDByPath(app_id, FPL("conflict_to_pending_remote"))));
1323 FetchRemoteChanges();
1325 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
1326 fake_drive_service_helper()->DeleteResource(
1327 GetFileIDByPath(app_id, FPL("conflict_to_existing_remote"))));
1329 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1330 VerifyConsistency();
1332 EXPECT_EQ(1u, CountApp());
1333 EXPECT_EQ(1u, CountLocalFile(app_id));
1335 EXPECT_EQ(2u, CountMetadata());
1336 EXPECT_EQ(2u, CountTracker());
1339 TEST_F(DriveBackendSyncTest, ConflictTest_AddFile_AddFolder) {
1340 std::string app_id = "example";
1342 RegisterApp(app_id);
1343 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL(""));
1345 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo");
1346 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar");
1348 std::string file_id;
1349 EXPECT_EQ(google_apis::HTTP_CREATED,
1350 fake_drive_service_helper()->AddFolder(
1351 app_root_folder_id, "conflict_to_pending_remote",
1352 &file_id));
1353 EXPECT_EQ(google_apis::HTTP_SUCCESS,
1354 fake_drive_service_helper()->UpdateModificationTime(
1355 file_id,
1356 base::Time::Now() - base::TimeDelta::FromDays(1)));
1358 FetchRemoteChanges();
1360 EXPECT_EQ(google_apis::HTTP_CREATED,
1361 fake_drive_service_helper()->AddFolder(
1362 app_root_folder_id, "conflict_to_existing_remote",
1363 &file_id));
1364 EXPECT_EQ(google_apis::HTTP_SUCCESS,
1365 fake_drive_service_helper()->UpdateModificationTime(
1366 file_id,
1367 base::Time::Now() - base::TimeDelta::FromDays(1)));
1369 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1370 VerifyConsistency();
1372 EXPECT_EQ(1u, CountApp());
1373 EXPECT_EQ(3u, CountLocalFile(app_id));
1374 VerifyLocalFolder(app_id, FPL("conflict_to_pending_remote"));
1375 VerifyLocalFolder(app_id, FPL("conflict_to_existing_remote"));
1377 EXPECT_EQ(4u, CountMetadata());
1378 EXPECT_EQ(4u, CountTracker());
1381 TEST_F(DriveBackendSyncTest, ConflictTest_AddFile_DeleteFolder) {
1382 std::string app_id = "example";
1384 RegisterApp(app_id);
1385 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL(""));
1387 AddLocalFolder(app_id, FPL("conflict_to_pending_remote"));
1388 AddLocalFolder(app_id, FPL("conflict_to_existing_remote"));
1390 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1391 VerifyConsistency();
1393 // Test body starts from here.
1394 RemoveLocal(app_id, FPL("conflict_to_pending_remote"));
1395 RemoveLocal(app_id, FPL("conflict_to_existing_remote"));
1396 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo");
1397 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar");
1399 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
1400 fake_drive_service_helper()->DeleteResource(
1401 GetFileIDByPath(app_id, FPL("conflict_to_pending_remote"))));
1403 FetchRemoteChanges();
1405 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
1406 fake_drive_service_helper()->DeleteResource(
1407 GetFileIDByPath(app_id, FPL("conflict_to_existing_remote"))));
1409 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1410 VerifyConsistency();
1412 EXPECT_EQ(1u, CountApp());
1413 EXPECT_EQ(3u, CountLocalFile(app_id));
1414 VerifyLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo");
1415 VerifyLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar");
1417 EXPECT_EQ(4u, CountMetadata());
1418 EXPECT_EQ(4u, CountTracker());
1421 TEST_F(DriveBackendSyncTest, ConflictTest_AddFile_AddFile) {
1422 std::string app_id = "example";
1424 RegisterApp(app_id);
1426 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL(""));
1427 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "hoge");
1428 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "fuga");
1430 std::string file_id;
1431 EXPECT_EQ(google_apis::HTTP_SUCCESS,
1432 fake_drive_service_helper()->AddFile(
1433 app_root_folder_id, "conflict_to_pending_remote", "foo",
1434 &file_id));
1435 EXPECT_EQ(google_apis::HTTP_SUCCESS,
1436 fake_drive_service_helper()->UpdateModificationTime(
1437 file_id,
1438 base::Time::Now() + base::TimeDelta::FromDays(1)));
1440 FetchRemoteChanges();
1442 EXPECT_EQ(google_apis::HTTP_SUCCESS,
1443 fake_drive_service_helper()->AddFile(
1444 app_root_folder_id, "conflict_to_existing_remote", "bar",
1445 &file_id));
1446 EXPECT_EQ(google_apis::HTTP_SUCCESS,
1447 fake_drive_service_helper()->UpdateModificationTime(
1448 file_id,
1449 base::Time::Now() + base::TimeDelta::FromDays(1)));
1451 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1452 VerifyConsistency();
1454 EXPECT_EQ(1u, CountApp());
1455 EXPECT_EQ(3u, CountLocalFile(app_id));
1456 VerifyLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo");
1457 VerifyLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar");
1459 EXPECT_EQ(4u, CountMetadata());
1460 EXPECT_EQ(4u, CountTracker());
1463 TEST_F(DriveBackendSyncTest, ConflictTest_AddFile_DeleteFile) {
1464 std::string app_id = "example";
1466 RegisterApp(app_id);
1468 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo");
1469 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar");
1471 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1472 VerifyConsistency();
1474 // Test body starts from here.
1475 RemoveLocal(app_id, FPL("conflict_to_pending_remote"));
1476 RemoveLocal(app_id, FPL("conflict_to_existing_remote"));
1477 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "hoge");
1478 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "fuga");
1480 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
1481 fake_drive_service_helper()->DeleteResource(
1482 GetFileIDByPath(app_id, FPL("conflict_to_pending_remote"))));
1484 FetchRemoteChanges();
1486 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
1487 fake_drive_service_helper()->DeleteResource(
1488 GetFileIDByPath(app_id, FPL("conflict_to_existing_remote"))));
1490 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1491 VerifyConsistency();
1493 EXPECT_EQ(1u, CountApp());
1494 EXPECT_EQ(3u, CountLocalFile(app_id));
1495 VerifyLocalFile(app_id, FPL("conflict_to_pending_remote"), "hoge");
1496 VerifyLocalFile(app_id, FPL("conflict_to_existing_remote"), "fuga");
1498 EXPECT_EQ(4u, CountMetadata());
1499 EXPECT_EQ(4u, CountTracker());
1502 TEST_F(DriveBackendSyncTest, ConflictTest_UpdateFile_DeleteFile) {
1503 std::string app_id = "example";
1505 RegisterApp(app_id);
1507 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo");
1508 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar");
1510 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1511 VerifyConsistency();
1513 // Test body starts from here.
1514 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "hoge");
1515 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "fuga");
1517 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
1518 fake_drive_service_helper()->DeleteResource(
1519 GetFileIDByPath(app_id, FPL("conflict_to_pending_remote"))));
1521 FetchRemoteChanges();
1523 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
1524 fake_drive_service_helper()->DeleteResource(
1525 GetFileIDByPath(app_id, FPL("conflict_to_existing_remote"))));
1527 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1528 VerifyConsistency();
1530 EXPECT_EQ(1u, CountApp());
1531 EXPECT_EQ(3u, CountLocalFile(app_id));
1532 VerifyLocalFile(app_id, FPL("conflict_to_pending_remote"), "hoge");
1533 VerifyLocalFile(app_id, FPL("conflict_to_existing_remote"), "fuga");
1535 EXPECT_EQ(4u, CountMetadata());
1536 EXPECT_EQ(4u, CountTracker());
1539 TEST_F(DriveBackendSyncTest, ConflictTest_DeleteFile_AddFolder) {
1540 std::string app_id = "example";
1542 RegisterApp(app_id);
1544 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL(""));
1545 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo");
1546 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar");
1548 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1549 VerifyConsistency();
1551 // Test body starts from here.
1552 RemoveLocal(app_id, FPL("conflict_to_pending_remote"));
1553 RemoveLocal(app_id, FPL("conflict_to_existing_remote"));
1555 EXPECT_EQ(google_apis::HTTP_CREATED,
1556 fake_drive_service_helper()->AddFolder(
1557 app_root_folder_id, "conflict_to_pending_remote", nullptr));
1559 FetchRemoteChanges();
1561 EXPECT_EQ(google_apis::HTTP_CREATED,
1562 fake_drive_service_helper()->AddFolder(
1563 app_root_folder_id, "conflict_to_existing_remote", nullptr));
1565 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1566 VerifyConsistency();
1568 EXPECT_EQ(1u, CountApp());
1569 EXPECT_EQ(3u, CountLocalFile(app_id));
1570 VerifyLocalFolder(app_id, FPL("conflict_to_pending_remote"));
1571 VerifyLocalFolder(app_id, FPL("conflict_to_existing_remote"));
1573 EXPECT_EQ(4u, CountMetadata());
1574 EXPECT_EQ(4u, CountTracker());
1577 TEST_F(DriveBackendSyncTest, ConflictTest_DeleteFile_DeleteFolder) {
1578 std::string app_id = "example";
1580 RegisterApp(app_id);
1582 AddLocalFolder(app_id, FPL("conflict_to_pending_remote"));
1583 AddLocalFolder(app_id, FPL("conflict_to_existing_remote"));
1585 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1586 VerifyConsistency();
1588 // Test body starts from here.
1589 RemoveLocal(app_id, FPL("conflict_to_pending_remote"));
1590 RemoveLocal(app_id, FPL("conflict_to_existing_remote"));
1592 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo");
1593 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar");
1595 RemoveLocal(app_id, FPL("conflict_to_pending_remote"));
1596 RemoveLocal(app_id, FPL("conflict_to_existing_remote"));
1598 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
1599 fake_drive_service_helper()->DeleteResource(
1600 GetFileIDByPath(app_id, FPL("conflict_to_pending_remote"))));
1602 FetchRemoteChanges();
1604 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
1605 fake_drive_service_helper()->DeleteResource(
1606 GetFileIDByPath(app_id, FPL("conflict_to_existing_remote"))));
1608 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1609 VerifyConsistency();
1611 EXPECT_EQ(1u, CountApp());
1612 EXPECT_EQ(1u, CountLocalFile(app_id));
1614 EXPECT_EQ(2u, CountMetadata());
1615 EXPECT_EQ(2u, CountTracker());
1618 TEST_F(DriveBackendSyncTest, ConflictTest_DeleteFile_AddFile) {
1619 std::string app_id = "example";
1621 RegisterApp(app_id);
1623 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL(""));
1624 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo");
1625 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar");
1626 RemoveLocal(app_id, FPL("conflict_to_pending_remote"));
1627 RemoveLocal(app_id, FPL("conflict_to_existing_remote"));
1629 EXPECT_EQ(google_apis::HTTP_SUCCESS,
1630 fake_drive_service_helper()->AddFile(
1631 app_root_folder_id, "conflict_to_pending_remote", "hoge",
1632 nullptr));
1634 FetchRemoteChanges();
1636 EXPECT_EQ(google_apis::HTTP_SUCCESS,
1637 fake_drive_service_helper()->AddFile(
1638 app_root_folder_id, "conflict_to_existing_remote", "fuga",
1639 nullptr));
1641 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1642 VerifyConsistency();
1644 EXPECT_EQ(1u, CountApp());
1645 EXPECT_EQ(3u, CountLocalFile(app_id));
1646 VerifyLocalFile(app_id, FPL("conflict_to_pending_remote"), "hoge");
1647 VerifyLocalFile(app_id, FPL("conflict_to_existing_remote"), "fuga");
1649 EXPECT_EQ(4u, CountMetadata());
1650 EXPECT_EQ(4u, CountTracker());
1653 TEST_F(DriveBackendSyncTest, ConflictTest_DeleteFile_UpdateFile) {
1654 std::string app_id = "example";
1656 RegisterApp(app_id);
1658 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL(""));
1659 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo");
1660 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar");
1662 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1663 VerifyConsistency();
1665 // Test body starts from here.
1666 RemoveLocal(app_id, FPL("conflict_to_pending_remote"));
1667 RemoveLocal(app_id, FPL("conflict_to_existing_remote"));
1669 EXPECT_EQ(google_apis::HTTP_SUCCESS,
1670 fake_drive_service_helper()->UpdateFile(
1671 GetFileIDByPath(app_id, FPL("conflict_to_pending_remote")),
1672 "hoge"));
1674 FetchRemoteChanges();
1676 EXPECT_EQ(google_apis::HTTP_SUCCESS,
1677 fake_drive_service_helper()->UpdateFile(
1678 GetFileIDByPath(app_id, FPL("conflict_to_existing_remote")),
1679 "fuga"));
1681 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1682 VerifyConsistency();
1684 EXPECT_EQ(1u, CountApp());
1685 EXPECT_EQ(3u, CountLocalFile(app_id));
1686 VerifyLocalFile(app_id, FPL("conflict_to_pending_remote"), "hoge");
1687 VerifyLocalFile(app_id, FPL("conflict_to_existing_remote"), "fuga");
1689 EXPECT_EQ(4u, CountMetadata());
1690 EXPECT_EQ(4u, CountTracker());
1693 TEST_F(DriveBackendSyncTest, ConflictTest_DeleteFile_DeleteFile) {
1694 std::string app_id = "example";
1696 RegisterApp(app_id);
1698 std::string app_root_folder_id = GetFileIDByPath(app_id, FPL(""));
1699 AddOrUpdateLocalFile(app_id, FPL("conflict_to_pending_remote"), "foo");
1700 AddOrUpdateLocalFile(app_id, FPL("conflict_to_existing_remote"), "bar");
1702 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1703 VerifyConsistency();
1705 // Test body starts from here.
1706 RemoveLocal(app_id, FPL("conflict_to_pending_remote"));
1707 RemoveLocal(app_id, FPL("conflict_to_existing_remote"));
1709 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
1710 fake_drive_service_helper()->DeleteResource(
1711 GetFileIDByPath(app_id, FPL("conflict_to_pending_remote"))));
1713 FetchRemoteChanges();
1715 EXPECT_EQ(google_apis::HTTP_NO_CONTENT,
1716 fake_drive_service_helper()->DeleteResource(
1717 GetFileIDByPath(app_id, FPL("conflict_to_existing_remote"))));
1719 EXPECT_EQ(SYNC_STATUS_OK, ProcessChangesUntilDone());
1720 VerifyConsistency();
1722 EXPECT_EQ(1u, CountApp());
1723 EXPECT_EQ(1u, CountLocalFile(app_id));
1725 EXPECT_EQ(2u, CountMetadata());
1726 EXPECT_EQ(2u, CountTracker());
1729 } // namespace drive_backend
1730 } // namespace sync_file_system