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

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

Issue 2613223002: Remove ScopedVector from base::JSONValueConverter (Closed)
Patch Set: Created 3 years, 11 months 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
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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 SyncStatusCode ListChanges() { 230 SyncStatusCode ListChanges() {
231 SyncStatusCode status = SYNC_STATUS_UNKNOWN; 231 SyncStatusCode status = SYNC_STATUS_UNKNOWN;
232 sync_task_manager_->ScheduleSyncTask( 232 sync_task_manager_->ScheduleSyncTask(
233 FROM_HERE, 233 FROM_HERE,
234 std::unique_ptr<SyncTask>(new ListChangesTask(context_.get())), 234 std::unique_ptr<SyncTask>(new ListChangesTask(context_.get())),
235 SyncTaskManager::PRIORITY_MED, CreateResultReceiver(&status)); 235 SyncTaskManager::PRIORITY_MED, CreateResultReceiver(&status));
236 base::RunLoop().RunUntilIdle(); 236 base::RunLoop().RunUntilIdle();
237 return status; 237 return status;
238 } 238 }
239 239
240 ScopedVector<google_apis::FileResource> 240 std::vector<std::unique_ptr<google_apis::FileResource>>
241 GetResourceEntriesForParentAndTitle(const std::string& parent_folder_id, 241 GetResourceEntriesForParentAndTitle(const std::string& parent_folder_id,
242 const std::string& title) { 242 const std::string& title) {
243 ScopedVector<google_apis::FileResource> entries; 243 std::vector<std::unique_ptr<google_apis::FileResource>> entries;
244 EXPECT_EQ(google_apis::HTTP_SUCCESS, 244 EXPECT_EQ(google_apis::HTTP_SUCCESS,
245 fake_drive_helper_->SearchByTitle( 245 fake_drive_helper_->SearchByTitle(
246 parent_folder_id, title, &entries)); 246 parent_folder_id, title, &entries));
247 return entries; 247 return entries;
248 } 248 }
249 249
250 void VerifyConflictResolution( 250 void VerifyConflictResolution(
251 const std::string& parent_folder_id, 251 const std::string& parent_folder_id,
252 const std::string& title, 252 const std::string& title,
253 const std::string& primary_file_id, 253 const std::string& primary_file_id,
254 test_util::FileResourceKind kind) { 254 test_util::FileResourceKind kind) {
255 ScopedVector<google_apis::FileResource> entries; 255 std::vector<std::unique_ptr<google_apis::FileResource>> entries;
256 EXPECT_EQ(google_apis::HTTP_SUCCESS, 256 EXPECT_EQ(google_apis::HTTP_SUCCESS,
257 fake_drive_helper_->SearchByTitle( 257 fake_drive_helper_->SearchByTitle(
258 parent_folder_id, title, &entries)); 258 parent_folder_id, title, &entries));
259 ASSERT_EQ(1u, entries.size()); 259 ASSERT_EQ(1u, entries.size());
260 EXPECT_EQ(primary_file_id, entries[0]->file_id()); 260 EXPECT_EQ(primary_file_id, entries[0]->file_id());
261 EXPECT_EQ(kind, test_util::GetFileResourceKind(*entries[0])); 261 EXPECT_EQ(kind, test_util::GetFileResourceKind(*entries[0]));
262 } 262 }
263 263
264 void VerifyLocalChangeConsistency( 264 void VerifyLocalChangeConsistency(
265 const URLToFileChangesMap& expected_changes) { 265 const URLToFileChangesMap& expected_changes) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 RunRemoteToLocalSyncerUntilIdle(); 300 RunRemoteToLocalSyncerUntilIdle();
301 301
302 const std::string kTitle = "foo"; 302 const std::string kTitle = "foo";
303 const std::string primary = CreateRemoteFile(app_root, kTitle, "data1"); 303 const std::string primary = CreateRemoteFile(app_root, kTitle, "data1");
304 CreateRemoteFile(app_root, kTitle, "data2"); 304 CreateRemoteFile(app_root, kTitle, "data2");
305 CreateRemoteFile(app_root, kTitle, "data3"); 305 CreateRemoteFile(app_root, kTitle, "data3");
306 CreateRemoteFile(app_root, kTitle, "data4"); 306 CreateRemoteFile(app_root, kTitle, "data4");
307 EXPECT_EQ(SYNC_STATUS_OK, ListChanges()); 307 EXPECT_EQ(SYNC_STATUS_OK, ListChanges());
308 RunRemoteToLocalSyncerUntilIdle(); 308 RunRemoteToLocalSyncerUntilIdle();
309 309
310 ScopedVector<google_apis::FileResource> entries = 310 std::vector<std::unique_ptr<google_apis::FileResource>> entries =
311 GetResourceEntriesForParentAndTitle(app_root, kTitle); 311 GetResourceEntriesForParentAndTitle(app_root, kTitle);
312 ASSERT_EQ(4u, entries.size()); 312 ASSERT_EQ(4u, entries.size());
313 313
314 // Only primary file should survive. 314 // Only primary file should survive.
315 EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver()); 315 EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver());
316 VerifyConflictResolution(app_root, kTitle, primary, 316 VerifyConflictResolution(app_root, kTitle, primary,
317 test_util::RESOURCE_KIND_FILE); 317 test_util::RESOURCE_KIND_FILE);
318 } 318 }
319 319
320 TEST_F(ConflictResolverTest, ResolveConflict_Folders) { 320 TEST_F(ConflictResolverTest, ResolveConflict_Folders) {
321 const GURL kOrigin("chrome-extension://example"); 321 const GURL kOrigin("chrome-extension://example");
322 const std::string sync_root = CreateSyncRoot(); 322 const std::string sync_root = CreateSyncRoot();
323 const std::string app_root = CreateRemoteFolder(sync_root, kOrigin.host()); 323 const std::string app_root = CreateRemoteFolder(sync_root, kOrigin.host());
324 InitializeMetadataDatabase(); 324 InitializeMetadataDatabase();
325 RegisterApp(kOrigin.host(), app_root); 325 RegisterApp(kOrigin.host(), app_root);
326 RunRemoteToLocalSyncerUntilIdle(); 326 RunRemoteToLocalSyncerUntilIdle();
327 327
328 const std::string kTitle = "foo"; 328 const std::string kTitle = "foo";
329 const std::string primary = CreateRemoteFolder(app_root, kTitle); 329 const std::string primary = CreateRemoteFolder(app_root, kTitle);
330 CreateRemoteFolder(app_root, kTitle); 330 CreateRemoteFolder(app_root, kTitle);
331 CreateRemoteFolder(app_root, kTitle); 331 CreateRemoteFolder(app_root, kTitle);
332 CreateRemoteFolder(app_root, kTitle); 332 CreateRemoteFolder(app_root, kTitle);
333 EXPECT_EQ(SYNC_STATUS_OK, ListChanges()); 333 EXPECT_EQ(SYNC_STATUS_OK, ListChanges());
334 RunRemoteToLocalSyncerUntilIdle(); 334 RunRemoteToLocalSyncerUntilIdle();
335 335
336 ScopedVector<google_apis::FileResource> entries = 336 std::vector<std::unique_ptr<google_apis::FileResource>> entries =
337 GetResourceEntriesForParentAndTitle(app_root, kTitle); 337 GetResourceEntriesForParentAndTitle(app_root, kTitle);
338 ASSERT_EQ(4u, entries.size()); 338 ASSERT_EQ(4u, entries.size());
339 339
340 // Only primary file should survive. 340 // Only primary file should survive.
341 EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver()); 341 EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver());
342 VerifyConflictResolution(app_root, kTitle, primary, 342 VerifyConflictResolution(app_root, kTitle, primary,
343 test_util::RESOURCE_KIND_FOLDER); 343 test_util::RESOURCE_KIND_FOLDER);
344 } 344 }
345 345
346 TEST_F(ConflictResolverTest, ResolveConflict_FilesAndFolders) { 346 TEST_F(ConflictResolverTest, ResolveConflict_FilesAndFolders) {
347 const GURL kOrigin("chrome-extension://example"); 347 const GURL kOrigin("chrome-extension://example");
348 const std::string sync_root = CreateSyncRoot(); 348 const std::string sync_root = CreateSyncRoot();
349 const std::string app_root = CreateRemoteFolder(sync_root, kOrigin.host()); 349 const std::string app_root = CreateRemoteFolder(sync_root, kOrigin.host());
350 InitializeMetadataDatabase(); 350 InitializeMetadataDatabase();
351 RegisterApp(kOrigin.host(), app_root); 351 RegisterApp(kOrigin.host(), app_root);
352 RunRemoteToLocalSyncerUntilIdle(); 352 RunRemoteToLocalSyncerUntilIdle();
353 353
354 const std::string kTitle = "foo"; 354 const std::string kTitle = "foo";
355 CreateRemoteFile(app_root, kTitle, "data"); 355 CreateRemoteFile(app_root, kTitle, "data");
356 const std::string primary = CreateRemoteFolder(app_root, kTitle); 356 const std::string primary = CreateRemoteFolder(app_root, kTitle);
357 CreateRemoteFile(app_root, kTitle, "data2"); 357 CreateRemoteFile(app_root, kTitle, "data2");
358 CreateRemoteFolder(app_root, kTitle); 358 CreateRemoteFolder(app_root, kTitle);
359 EXPECT_EQ(SYNC_STATUS_OK, ListChanges()); 359 EXPECT_EQ(SYNC_STATUS_OK, ListChanges());
360 RunRemoteToLocalSyncerUntilIdle(); 360 RunRemoteToLocalSyncerUntilIdle();
361 361
362 ScopedVector<google_apis::FileResource> entries = 362 std::vector<std::unique_ptr<google_apis::FileResource>> entries =
363 GetResourceEntriesForParentAndTitle(app_root, kTitle); 363 GetResourceEntriesForParentAndTitle(app_root, kTitle);
364 ASSERT_EQ(4u, entries.size()); 364 ASSERT_EQ(4u, entries.size());
365 365
366 // Only primary file should survive. 366 // Only primary file should survive.
367 EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver()); 367 EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver());
368 VerifyConflictResolution(app_root, kTitle, primary, 368 VerifyConflictResolution(app_root, kTitle, primary,
369 test_util::RESOURCE_KIND_FOLDER); 369 test_util::RESOURCE_KIND_FOLDER);
370 } 370 }
371 371
372 TEST_F(ConflictResolverTest, ResolveConflict_RemoteFolderOnLocalFile) { 372 TEST_F(ConflictResolverTest, ResolveConflict_RemoteFolderOnLocalFile) {
(...skipping 11 matching lines...) Expand all
384 CreateLocalFile(kURL); 384 CreateLocalFile(kURL);
385 RunLocalToRemoteSyncer( 385 RunLocalToRemoteSyncer(
386 kURL, 386 kURL,
387 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE)); 387 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE));
388 388
389 // Create a folder on remote and sync it. 389 // Create a folder on remote and sync it.
390 const std::string primary = CreateRemoteFolder(app_root, kTitle); 390 const std::string primary = CreateRemoteFolder(app_root, kTitle);
391 EXPECT_EQ(SYNC_STATUS_OK, ListChanges()); 391 EXPECT_EQ(SYNC_STATUS_OK, ListChanges());
392 RunRemoteToLocalSyncerUntilIdle(); 392 RunRemoteToLocalSyncerUntilIdle();
393 393
394 ScopedVector<google_apis::FileResource> entries = 394 std::vector<std::unique_ptr<google_apis::FileResource>> entries =
395 GetResourceEntriesForParentAndTitle(app_root, kTitle); 395 GetResourceEntriesForParentAndTitle(app_root, kTitle);
396 ASSERT_EQ(2u, entries.size()); 396 ASSERT_EQ(2u, entries.size());
397 397
398 // Run conflict resolver. Only primary file should survive. 398 // Run conflict resolver. Only primary file should survive.
399 EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver()); 399 EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver());
400 VerifyConflictResolution(app_root, kTitle, primary, 400 VerifyConflictResolution(app_root, kTitle, primary,
401 test_util::RESOURCE_KIND_FOLDER); 401 test_util::RESOURCE_KIND_FOLDER);
402 402
403 // Continue to run remote-to-local sync. 403 // Continue to run remote-to-local sync.
404 EXPECT_EQ(SYNC_STATUS_OK, ListChanges()); 404 EXPECT_EQ(SYNC_STATUS_OK, ListChanges());
(...skipping 27 matching lines...) Expand all
432 RunLocalToRemoteSyncer( 432 RunLocalToRemoteSyncer(
433 kURL, 433 kURL,
434 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE)); 434 FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, SYNC_FILE_TYPE_FILE));
435 435
436 // Create a folder and subfolder in it on remote, and sync it. 436 // Create a folder and subfolder in it on remote, and sync it.
437 const std::string primary = CreateRemoteFolder(app_root, kTitle); 437 const std::string primary = CreateRemoteFolder(app_root, kTitle);
438 CreateRemoteFolder(primary, "nested"); 438 CreateRemoteFolder(primary, "nested");
439 EXPECT_EQ(SYNC_STATUS_OK, ListChanges()); 439 EXPECT_EQ(SYNC_STATUS_OK, ListChanges());
440 RunRemoteToLocalSyncerUntilIdle(); 440 RunRemoteToLocalSyncerUntilIdle();
441 441
442 ScopedVector<google_apis::FileResource> entries = 442 std::vector<std::unique_ptr<google_apis::FileResource>> entries =
443 GetResourceEntriesForParentAndTitle(app_root, kTitle); 443 GetResourceEntriesForParentAndTitle(app_root, kTitle);
444 ASSERT_EQ(2u, entries.size()); 444 ASSERT_EQ(2u, entries.size());
445 445
446 // Run conflict resolver. Only primary file should survive. 446 // Run conflict resolver. Only primary file should survive.
447 EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver()); 447 EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver());
448 VerifyConflictResolution(app_root, kTitle, primary, 448 VerifyConflictResolution(app_root, kTitle, primary,
449 test_util::RESOURCE_KIND_FOLDER); 449 test_util::RESOURCE_KIND_FOLDER);
450 450
451 // Continue to run remote-to-local sync. 451 // Continue to run remote-to-local sync.
452 EXPECT_EQ(SYNC_STATUS_OK, ListChanges()); 452 EXPECT_EQ(SYNC_STATUS_OK, ListChanges());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 516
517 EXPECT_EQ(4, CountParents(file)); 517 EXPECT_EQ(4, CountParents(file));
518 518
519 EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver()); 519 EXPECT_EQ(SYNC_STATUS_OK, RunConflictResolver());
520 520
521 EXPECT_EQ(1, CountParents(file)); 521 EXPECT_EQ(1, CountParents(file));
522 } 522 }
523 523
524 } // namespace drive_backend 524 } // namespace drive_backend
525 } // namespace sync_file_system 525 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698