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

Side by Side Diff: chrome/browser/sync_file_system/local/local_file_sync_service_unittest.cc

Issue 23578026: Use SNAPSHOT sync mode for LocalSync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased on thread_bundle fix Created 7 years, 3 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 | Annotate | Revision Log
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 <vector> 5 #include <vector>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 file_system2.TearDown(); 314 file_system2.TearDown();
315 } 315 }
316 316
317 TEST_F(LocalFileSyncServiceTest, ProcessLocalChange_CreateFile) { 317 TEST_F(LocalFileSyncServiceTest, ProcessLocalChange_CreateFile) {
318 const FileSystemURL kFile(file_system_->URL("foo")); 318 const FileSystemURL kFile(file_system_->URL("foo"));
319 const char kTestFileData[] = "0123456789"; 319 const char kTestFileData[] = "0123456789";
320 const int kTestFileDataSize = static_cast<int>(arraysize(kTestFileData) - 1); 320 const int kTestFileDataSize = static_cast<int>(arraysize(kTestFileData) - 1);
321 321
322 base::RunLoop run_loop; 322 base::RunLoop run_loop;
323 323
324 // We should get called OnSyncEnabled on kFile. 324 // We should get called OnSyncEnabled and OnWriteEnabled on kFile.
325 // (OnWriteEnabled is called because we release lock before returning
326 // from ApplyLocalChange)
325 StrictMock<MockSyncStatusObserver> status_observer; 327 StrictMock<MockSyncStatusObserver> status_observer;
326 EXPECT_CALL(status_observer, OnSyncEnabled(kFile)) 328 EXPECT_CALL(status_observer, OnSyncEnabled(kFile)).Times(AtLeast(1));
327 .Times(AtLeast(1)); 329 EXPECT_CALL(status_observer, OnWriteEnabled(kFile)).Times(AtLeast(1));
328 file_system_->AddSyncStatusObserver(&status_observer); 330 file_system_->AddSyncStatusObserver(&status_observer);
329 331
330 // Creates and writes into a file. 332 // Creates and writes into a file.
331 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_->CreateFile(kFile)); 333 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_->CreateFile(kFile));
332 EXPECT_EQ(kTestFileDataSize, 334 EXPECT_EQ(kTestFileDataSize,
333 file_system_->WriteString(kFile, std::string(kTestFileData))); 335 file_system_->WriteString(kFile, std::string(kTestFileData)));
334 336
335 // Retrieve the expected platform_path. 337 // Retrieve the expected file info.
336 base::PlatformFileInfo info; 338 base::PlatformFileInfo info;
337 base::FilePath platform_path; 339 base::FilePath platform_path;
338 EXPECT_EQ(base::PLATFORM_FILE_OK, 340 EXPECT_EQ(base::PLATFORM_FILE_OK,
339 file_system_->GetMetadataAndPlatformPath( 341 file_system_->GetMetadataAndPlatformPath(
340 kFile, &info, &platform_path)); 342 kFile, &info, &platform_path));
341 343
342 ASSERT_FALSE(info.is_directory); 344 ASSERT_FALSE(info.is_directory);
343 ASSERT_EQ(kTestFileDataSize, info.size); 345 ASSERT_EQ(kTestFileDataSize, info.size);
344 346
345 SyncFileMetadata metadata; 347 SyncFileMetadata metadata;
346 metadata.file_type = SYNC_FILE_TYPE_FILE; 348 metadata.file_type = SYNC_FILE_TYPE_FILE;
347 metadata.size = info.size; 349 metadata.size = info.size;
348 metadata.last_modified = info.last_modified; 350 metadata.last_modified = info.last_modified;
349 351
350 // The local_change_processor's ApplyLocalChange should be called once 352 // The local_change_processor's ApplyLocalChange should be called once
351 // with ADD_OR_UPDATE change for TYPE_FILE. 353 // with ADD_OR_UPDATE change for TYPE_FILE.
352 StrictMock<MockLocalChangeProcessor> local_change_processor; 354 StrictMock<MockLocalChangeProcessor> local_change_processor;
353 const FileChange change(FileChange::FILE_CHANGE_ADD_OR_UPDATE, 355 const FileChange change(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
354 SYNC_FILE_TYPE_FILE); 356 SYNC_FILE_TYPE_FILE);
355 EXPECT_CALL(local_change_processor, 357 EXPECT_CALL(local_change_processor,
356 ApplyLocalChange(change, platform_path, metadata, kFile, _)) 358 ApplyLocalChange(change, _, metadata, kFile, _))
357 .WillOnce(MockStatusCallback(SYNC_STATUS_OK)); 359 .WillOnce(MockStatusCallback(SYNC_STATUS_OK));
358 360
359 local_service_->SetLocalChangeProcessor(&local_change_processor); 361 local_service_->SetLocalChangeProcessor(&local_change_processor);
360 local_service_->ProcessLocalChange( 362 local_service_->ProcessLocalChange(
361 base::Bind(&OnSyncCompleted, FROM_HERE, run_loop.QuitClosure(), 363 base::Bind(&OnSyncCompleted, FROM_HERE, run_loop.QuitClosure(),
362 SYNC_STATUS_OK, kFile)); 364 SYNC_STATUS_OK, kFile));
363 365
364 run_loop.Run(); 366 run_loop.Run();
365 367
366 file_system_->RemoveSyncStatusObserver(&status_observer); 368 file_system_->RemoveSyncStatusObserver(&status_observer);
367 369
368 EXPECT_EQ(0, GetNumChangesInTracker()); 370 EXPECT_EQ(0, GetNumChangesInTracker());
369 } 371 }
370 372
371 TEST_F(LocalFileSyncServiceTest, ProcessLocalChange_CreateAndRemoveFile) { 373 TEST_F(LocalFileSyncServiceTest, ProcessLocalChange_CreateAndRemoveFile) {
372 const FileSystemURL kFile(file_system_->URL("foo")); 374 const FileSystemURL kFile(file_system_->URL("foo"));
373 375
374 base::RunLoop run_loop; 376 base::RunLoop run_loop;
375 377
376 // We should get called OnSyncEnabled and OnWriteEnabled on kFile. 378 // We should get called OnSyncEnabled and OnWriteEnabled on kFile.
377 StrictMock<MockSyncStatusObserver> status_observer; 379 StrictMock<MockSyncStatusObserver> status_observer;
378 EXPECT_CALL(status_observer, OnSyncEnabled(kFile)) 380 EXPECT_CALL(status_observer, OnSyncEnabled(kFile)).Times(AtLeast(1));
379 .Times(AtLeast(1)); 381 EXPECT_CALL(status_observer, OnWriteEnabled(kFile)).Times(AtLeast(1));
380 file_system_->AddSyncStatusObserver(&status_observer); 382 file_system_->AddSyncStatusObserver(&status_observer);
381 383
382 // Creates and then deletes a file. 384 // Creates and then deletes a file.
383 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_->CreateFile(kFile)); 385 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_->CreateFile(kFile));
384 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_->Remove(kFile, false)); 386 EXPECT_EQ(base::PLATFORM_FILE_OK, file_system_->Remove(kFile, false));
385 387
386 // The local_change_processor's ApplyLocalChange should be called once 388 // The local_change_processor's ApplyLocalChange should be called once
387 // with DELETE change for TYPE_FILE. 389 // with DELETE change for TYPE_FILE.
388 // The file will NOT exist in the remote side and the processor might 390 // The file will NOT exist in the remote side and the processor might
389 // return SYNC_FILE_ERROR_NOT_FOUND (as mocked). 391 // return SYNC_FILE_ERROR_NOT_FOUND (as mocked).
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 460
459 // The local_change_processor's ApplyLocalChange will be called 461 // The local_change_processor's ApplyLocalChange will be called
460 // twice for FILE_TYPE and FILE_DIRECTORY. 462 // twice for FILE_TYPE and FILE_DIRECTORY.
461 StrictMock<MockLocalChangeProcessor> local_change_processor; 463 StrictMock<MockLocalChangeProcessor> local_change_processor;
462 std::vector<FileChange> changes; 464 std::vector<FileChange> changes;
463 EXPECT_CALL(local_change_processor, ApplyLocalChange(_, _, _, kPath, _)) 465 EXPECT_CALL(local_change_processor, ApplyLocalChange(_, _, _, kPath, _))
464 .Times(2) 466 .Times(2)
465 .WillOnce(MockStatusCallbackAndRecordChange(SYNC_STATUS_OK, &changes)) 467 .WillOnce(MockStatusCallbackAndRecordChange(SYNC_STATUS_OK, &changes))
466 .WillOnce(MockStatusCallbackAndRecordChange(SYNC_STATUS_OK, &changes)); 468 .WillOnce(MockStatusCallbackAndRecordChange(SYNC_STATUS_OK, &changes));
467 local_service_->SetLocalChangeProcessor(&local_change_processor); 469 local_service_->SetLocalChangeProcessor(&local_change_processor);
470
471 // OnWriteEnabled will be notified on kPath.
472 EXPECT_CALL(status_observer, OnWriteEnabled(kPath)).Times(AtLeast(1));
473
468 local_service_->ProcessLocalChange( 474 local_service_->ProcessLocalChange(
469 base::Bind(&OnSyncCompleted, FROM_HERE, run_loop.QuitClosure(), 475 base::Bind(&OnSyncCompleted, FROM_HERE, run_loop.QuitClosure(),
470 SYNC_STATUS_OK, kPath)); 476 SYNC_STATUS_OK, kPath));
471 477
472 run_loop.Run(); 478 run_loop.Run();
473 479
474 EXPECT_EQ(2U, changes.size()); 480 EXPECT_EQ(2U, changes.size());
475 EXPECT_EQ(FileChange(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_FILE), 481 EXPECT_EQ(FileChange(FileChange::FILE_CHANGE_DELETE, SYNC_FILE_TYPE_FILE),
476 changes[0]); 482 changes[0]);
477 EXPECT_EQ(FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE, 483 EXPECT_EQ(FileChange(FileChange::FILE_CHANGE_ADD_OR_UPDATE,
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 all_origins.insert(kOrigin2); 709 all_origins.insert(kOrigin2);
704 all_origins.insert(kOrigin3); 710 all_origins.insert(kOrigin3);
705 while (!all_origins.empty()) { 711 while (!all_origins.empty()) {
706 ASSERT_TRUE(NextOriginToProcess(&origin)); 712 ASSERT_TRUE(NextOriginToProcess(&origin));
707 ASSERT_TRUE(ContainsKey(all_origins, origin)); 713 ASSERT_TRUE(ContainsKey(all_origins, origin));
708 all_origins.erase(origin); 714 all_origins.erase(origin);
709 } 715 }
710 } 716 }
711 717
712 } // namespace sync_file_system 718 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698