Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: chrome/browser/sync_file_system/drive_backend/conflict_resolver_unittest.cc

Issue 101283002: SyncFS: Fix conflict resolver for multiple parents (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/sync_file_system/drive_backend/conflict_resolver.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/sync_file_system/drive_backend/conflict_resolver.h" 5 #include "chrome/browser/sync_file_system/drive_backend/conflict_resolver.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 std::string CreateRemoteFile(const std::string& parent_folder_id, 133 std::string CreateRemoteFile(const std::string& parent_folder_id,
134 const std::string& title, 134 const std::string& title,
135 const std::string& content) { 135 const std::string& content) {
136 std::string file_id; 136 std::string file_id;
137 EXPECT_EQ(google_apis::HTTP_SUCCESS, 137 EXPECT_EQ(google_apis::HTTP_SUCCESS,
138 fake_drive_helper_->AddFile( 138 fake_drive_helper_->AddFile(
139 parent_folder_id, title, content, &file_id)); 139 parent_folder_id, title, content, &file_id));
140 return file_id; 140 return file_id;
141 } 141 }
142 142
143 google_apis::GDataErrorCode AddFileToFolder(
144 const std::string& parent_folder_id,
145 const std::string& file_id) {
146 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR;
147 fake_drive_service_->AddResourceToDirectory(
148 parent_folder_id, file_id,
149 CreateResultReceiver(&error));
150 base::RunLoop().RunUntilIdle();
151 return error;
152 }
153
154 int CountParents(const std::string& file_id) {
155 scoped_ptr<google_apis::ResourceEntry> entry;
156 EXPECT_EQ(google_apis::HTTP_SUCCESS,
157 fake_drive_helper_->GetResourceEntry(file_id, &entry));
158 int count = 0;
159 const ScopedVector<google_apis::Link>& links = entry->links();
160 for (ScopedVector<google_apis::Link>::const_iterator itr = links.begin();
161 itr != links.end(); ++itr) {
162 if ((*itr)->type() == google_apis::Link::LINK_PARENT)
163 ++count;
164 }
165 return count;
166 }
167
143 SyncStatusCode RunSyncer() { 168 SyncStatusCode RunSyncer() {
144 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 169 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
145 scoped_ptr<RemoteToLocalSyncer> syncer(new RemoteToLocalSyncer(this)); 170 scoped_ptr<RemoteToLocalSyncer> syncer(new RemoteToLocalSyncer(this));
146 syncer->Run(CreateResultReceiver(&status)); 171 syncer->Run(CreateResultReceiver(&status));
147 base::RunLoop().RunUntilIdle(); 172 base::RunLoop().RunUntilIdle();
148 return status; 173 return status;
149 } 174 }
150 175
151 void RunSyncerUntilIdle() { 176 void RunSyncerUntilIdle() {
152 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 177 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 ScopedVector<google_apis::ResourceEntry> entries = 313 ScopedVector<google_apis::ResourceEntry> entries =
289 GetResourceEntriesForParentAndTitle(app_root, kTitle); 314 GetResourceEntriesForParentAndTitle(app_root, kTitle);
290 ASSERT_EQ(4u, entries.size()); 315 ASSERT_EQ(4u, entries.size());
291 316
292 // Only primary file should survive. 317 // Only primary file should survive.
293 EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver()); 318 EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver());
294 VerifyConflictResolution(app_root, kTitle, primary, 319 VerifyConflictResolution(app_root, kTitle, primary,
295 google_apis::ENTRY_KIND_FOLDER); 320 google_apis::ENTRY_KIND_FOLDER);
296 } 321 }
297 322
298 // TODO(nhiroki): Add multi-parent resolution cases. 323 TEST_F(ConflictResolverTest, ResolveMultiParents_File) {
324 const GURL kOrigin("chrome-extension://example");
325 const std::string sync_root = CreateSyncRoot();
326 const std::string app_root = CreateRemoteFolder(sync_root, kOrigin.host());
327 InitializeMetadataDatabase();
328 RegisterApp(kOrigin.host(), app_root);
329 RunSyncerUntilIdle();
330
331 const std::string primary = CreateRemoteFolder(app_root, "primary");
332 const std::string file = CreateRemoteFile(primary, "file", "data");
333 ASSERT_EQ(google_apis::HTTP_SUCCESS,
334 AddFileToFolder(CreateRemoteFolder(app_root, "nonprimary1"), file));
335 ASSERT_EQ(google_apis::HTTP_SUCCESS,
336 AddFileToFolder(CreateRemoteFolder(app_root, "nonprimary2"), file));
337 ASSERT_EQ(google_apis::HTTP_SUCCESS,
338 AddFileToFolder(CreateRemoteFolder(app_root, "nonprimary3"), file));
339
340 EXPECT_EQ(SYNC_STATUS_OK, ListChanges());
341 RunSyncerUntilIdle();
342
343 EXPECT_EQ(4, CountParents(file));
344
345 EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver());
346
347 EXPECT_EQ(1, CountParents(file));
348 }
349
350 TEST_F(ConflictResolverTest, ResolveMultiParents_Folder) {
351 const GURL kOrigin("chrome-extension://example");
352 const std::string sync_root = CreateSyncRoot();
353 const std::string app_root = CreateRemoteFolder(sync_root, kOrigin.host());
354 InitializeMetadataDatabase();
355 RegisterApp(kOrigin.host(), app_root);
356 RunSyncerUntilIdle();
357
358 const std::string primary = CreateRemoteFolder(app_root, "primary");
359 const std::string file = CreateRemoteFolder(primary, "folder");
360 ASSERT_EQ(google_apis::HTTP_SUCCESS,
361 AddFileToFolder(CreateRemoteFolder(app_root, "nonprimary1"), file));
362 ASSERT_EQ(google_apis::HTTP_SUCCESS,
363 AddFileToFolder(CreateRemoteFolder(app_root, "nonprimary2"), file));
364 ASSERT_EQ(google_apis::HTTP_SUCCESS,
365 AddFileToFolder(CreateRemoteFolder(app_root, "nonprimary3"), file));
366
367 EXPECT_EQ(SYNC_STATUS_OK, ListChanges());
368 RunSyncerUntilIdle();
369
370 EXPECT_EQ(4, CountParents(file));
371
372 EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver());
373
374 EXPECT_EQ(1, CountParents(file));
375 }
299 376
300 } // namespace drive_backend 377 } // namespace drive_backend
301 } // namespace sync_file_system 378 } // namespace sync_file_system
OLDNEW
« no previous file with comments | « chrome/browser/sync_file_system/drive_backend/conflict_resolver.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698