Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_file_sync_service.h" | 5 #include "chrome/browser/sync_file_system/drive_file_sync_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "chrome/browser/sync_file_system/mock_remote_change_processor.h" | 23 #include "chrome/browser/sync_file_system/mock_remote_change_processor.h" |
| 24 #include "chrome/browser/sync_file_system/sync_file_system.pb.h" | 24 #include "chrome/browser/sync_file_system/sync_file_system.pb.h" |
| 25 #include "chrome/common/extensions/extension.h" | 25 #include "chrome/common/extensions/extension.h" |
| 26 #include "chrome/common/extensions/extension_builder.h" | 26 #include "chrome/common/extensions/extension_builder.h" |
| 27 #include "chrome/test/base/testing_profile.h" | 27 #include "chrome/test/base/testing_profile.h" |
| 28 #include "content/public/test/test_browser_thread.h" | 28 #include "content/public/test/test_browser_thread.h" |
| 29 #include "extensions/common/id_util.h" | 29 #include "extensions/common/id_util.h" |
| 30 #include "net/base/escape.h" | 30 #include "net/base/escape.h" |
| 31 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 33 #include "webkit/fileapi/file_system_util.h" | |
| 33 #include "webkit/fileapi/syncable/sync_direction.h" | 34 #include "webkit/fileapi/syncable/sync_direction.h" |
| 34 #include "webkit/fileapi/syncable/sync_file_metadata.h" | 35 #include "webkit/fileapi/syncable/sync_file_metadata.h" |
| 35 #include "webkit/fileapi/syncable/syncable_file_system_util.h" | 36 #include "webkit/fileapi/syncable/syncable_file_system_util.h" |
| 36 | 37 |
| 37 #if defined(OS_CHROMEOS) | 38 #if defined(OS_CHROMEOS) |
| 38 #include "chrome/browser/chromeos/login/user_manager.h" | 39 #include "chrome/browser/chromeos/login/user_manager.h" |
| 39 #include "chrome/browser/chromeos/settings/cros_settings.h" | 40 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 40 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 41 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 41 #endif | 42 #endif |
| 42 | 43 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 72 return base::FilePath().AppendASCII(path).value(); | 73 return base::FilePath().AppendASCII(path).value(); |
| 73 } | 74 } |
| 74 | 75 |
| 75 void DidInitialize(bool* done, SyncStatusCode status, bool created) { | 76 void DidInitialize(bool* done, SyncStatusCode status, bool created) { |
| 76 EXPECT_FALSE(*done); | 77 EXPECT_FALSE(*done); |
| 77 *done = true; | 78 *done = true; |
| 78 EXPECT_EQ(SYNC_STATUS_OK, status); | 79 EXPECT_EQ(SYNC_STATUS_OK, status); |
| 79 EXPECT_TRUE(created); | 80 EXPECT_TRUE(created); |
| 80 } | 81 } |
| 81 | 82 |
| 82 void DidUpdateEntry(SyncStatusCode status) { | |
| 83 EXPECT_EQ(SYNC_STATUS_OK, status); | |
| 84 } | |
| 85 | |
| 86 void DidGetSyncRoot(bool* done, | 83 void DidGetSyncRoot(bool* done, |
| 87 SyncStatusCode status, | 84 SyncStatusCode status, |
| 88 const std::string& resource_id) { | 85 const std::string& resource_id) { |
| 89 EXPECT_FALSE(*done); | 86 EXPECT_FALSE(*done); |
| 90 *done = true; | 87 *done = true; |
| 91 } | 88 } |
| 92 | 89 |
| 93 void ExpectEqStatus(bool* done, | 90 void ExpectEqStatus(bool* done, |
| 94 SyncStatusCode expected, | 91 SyncStatusCode expected, |
| 95 SyncStatusCode actual) { | 92 SyncStatusCode actual) { |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 extension_id, extension_misc::UNLOAD_REASON_UNINSTALL); | 340 extension_id, extension_misc::UNLOAD_REASON_UNINSTALL); |
| 344 } | 341 } |
| 345 | 342 |
| 346 void UpdateRegisteredOrigins() { | 343 void UpdateRegisteredOrigins() { |
| 347 sync_service_->UpdateRegisteredOrigins(); | 344 sync_service_->UpdateRegisteredOrigins(); |
| 348 // Wait for completion of uninstalling origin. | 345 // Wait for completion of uninstalling origin. |
| 349 message_loop()->RunUntilIdle(); | 346 message_loop()->RunUntilIdle(); |
| 350 } | 347 } |
| 351 | 348 |
| 352 void VerifySizeOfRegisteredOrigins( | 349 void VerifySizeOfRegisteredOrigins( |
| 353 DriveMetadataStore::ResourceIdByOrigin::size_type b_size, | 350 unsigned int b_size, |
| 354 DriveMetadataStore::ResourceIdByOrigin::size_type i_size, | 351 DriveMetadataStore::ResourceIdByOrigin::size_type i_size, |
| 355 DriveMetadataStore::ResourceIdByOrigin::size_type d_size) { | 352 DriveMetadataStore::ResourceIdByOrigin::size_type d_size) { |
|
tzik
2013/05/21 04:05:45
these three types can be just size_t.
calvinlo
2013/05/21 07:12:26
Done.
| |
| 356 EXPECT_EQ(b_size, metadata_store()->batch_sync_origins().size()); | 353 EXPECT_EQ(b_size, pending_batch_sync_origins()->size()); |
| 357 EXPECT_EQ(i_size, metadata_store()->incremental_sync_origins().size()); | 354 EXPECT_EQ(i_size, metadata_store()->incremental_sync_origins().size()); |
| 358 EXPECT_EQ(d_size, metadata_store()->disabled_origins().size()); | 355 EXPECT_EQ(d_size, metadata_store()->disabled_origins().size()); |
| 359 } | 356 } |
| 360 | 357 |
| 361 drive::APIUtilInterface* api_util() { | 358 drive::APIUtilInterface* api_util() { |
| 362 if (api_util_) | 359 if (api_util_) |
| 363 return api_util_.get(); | 360 return api_util_.get(); |
| 364 return sync_service_->api_util_.get(); | 361 return sync_service_->api_util_.get(); |
| 365 } | 362 } |
| 366 | 363 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 381 StrictMock<MockFileStatusObserver>* mock_file_status_observer() { | 378 StrictMock<MockFileStatusObserver>* mock_file_status_observer() { |
| 382 return &mock_file_status_observer_; | 379 return &mock_file_status_observer_; |
| 383 } | 380 } |
| 384 | 381 |
| 385 StrictMock<MockRemoteChangeProcessor>* mock_remote_processor() { | 382 StrictMock<MockRemoteChangeProcessor>* mock_remote_processor() { |
| 386 return &mock_remote_processor_; | 383 return &mock_remote_processor_; |
| 387 } | 384 } |
| 388 | 385 |
| 389 MessageLoop* message_loop() { return &message_loop_; } | 386 MessageLoop* message_loop() { return &message_loop_; } |
| 390 DriveFileSyncService* sync_service() { return sync_service_.get(); } | 387 DriveFileSyncService* sync_service() { return sync_service_.get(); } |
| 388 std::map<GURL, std::string>* pending_batch_sync_origins() { | |
| 389 return &(sync_service()->pending_batch_sync_origins_); | |
| 390 } | |
| 391 | 391 |
| 392 const RemoteChangeHandler& remote_change_handler() const { | 392 const RemoteChangeHandler& remote_change_handler() const { |
| 393 return sync_service_->remote_change_handler_; | 393 return sync_service_->remote_change_handler_; |
| 394 } | 394 } |
| 395 | 395 |
| 396 fileapi::FileSystemURL CreateURL(const GURL& origin, | 396 fileapi::FileSystemURL CreateURL(const GURL& origin, |
| 397 const base::FilePath::StringType& path) { | 397 const base::FilePath::StringType& path) { |
| 398 return CreateSyncableFileSystemURL( | 398 return CreateSyncableFileSystemURL( |
| 399 origin, kServiceName, base::FilePath(path)); | 399 origin, kServiceName, base::FilePath(path)); |
| 400 } | 400 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 516 } | 516 } |
| 517 | 517 |
| 518 void SetUpDriveServiceExpectCallsForGetAboutResource() { | 518 void SetUpDriveServiceExpectCallsForGetAboutResource() { |
| 519 scoped_ptr<Value> account_metadata_value(LoadJSONFile( | 519 scoped_ptr<Value> account_metadata_value(LoadJSONFile( |
| 520 "chromeos/gdata/account_metadata.json")); | 520 "chromeos/gdata/account_metadata.json")); |
| 521 scoped_ptr<google_apis::AboutResource> about_resource( | 521 scoped_ptr<google_apis::AboutResource> about_resource( |
| 522 google_apis::AboutResource::CreateFromAccountMetadata( | 522 google_apis::AboutResource::CreateFromAccountMetadata( |
| 523 *google_apis::AccountMetadata::CreateFrom(*account_metadata_value), | 523 *google_apis::AccountMetadata::CreateFrom(*account_metadata_value), |
| 524 kRootResourceId)); | 524 kRootResourceId)); |
| 525 EXPECT_CALL(*mock_drive_service(), GetAboutResource(_)) | 525 EXPECT_CALL(*mock_drive_service(), GetAboutResource(_)) |
| 526 .WillOnce(InvokeGetAboutResourceCallback0( | 526 .Times(AnyNumber()) |
| 527 .WillRepeatedly(InvokeGetAboutResourceCallback0( | |
| 527 google_apis::HTTP_SUCCESS, | 528 google_apis::HTTP_SUCCESS, |
| 528 base::Passed(&about_resource))) | 529 base::Passed(&about_resource))); |
|
tzik
2013/05/21 04:05:45
Passed scoped_ptr can be used only once. So, secon
calvinlo
2013/05/21 07:12:26
Done.
| |
| 529 .RetiresOnSaturation(); | |
| 530 } | 530 } |
| 531 | 531 |
| 532 void SetUpDriveServiceExpectCallsForDownloadFile( | 532 void SetUpDriveServiceExpectCallsForDownloadFile( |
| 533 const std::string& file_resource_id) { | 533 const std::string& file_resource_id) { |
| 534 scoped_ptr<Value> file_entry_value( | 534 scoped_ptr<Value> file_entry_value( |
| 535 LoadJSONFile("chromeos/gdata/file_entry.json").Pass()); | 535 LoadJSONFile("chromeos/gdata/file_entry.json").Pass()); |
| 536 scoped_ptr<google_apis::ResourceEntry> file_entry | 536 scoped_ptr<google_apis::ResourceEntry> file_entry |
| 537 = google_apis::ResourceEntry::ExtractAndParse(*file_entry_value); | 537 = google_apis::ResourceEntry::ExtractAndParse(*file_entry_value); |
| 538 EXPECT_CALL(*mock_drive_service(), | 538 EXPECT_CALL(*mock_drive_service(), |
| 539 GetResourceEntry(file_resource_id, _)) | 539 GetResourceEntry(file_resource_id, _)) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 StrictMock<MockRemoteChangeProcessor> mock_remote_processor_; | 593 StrictMock<MockRemoteChangeProcessor> mock_remote_processor_; |
| 594 | 594 |
| 595 scoped_ptr<drive::APIUtil> api_util_; | 595 scoped_ptr<drive::APIUtil> api_util_; |
| 596 scoped_ptr<DriveMetadataStore> metadata_store_; | 596 scoped_ptr<DriveMetadataStore> metadata_store_; |
| 597 | 597 |
| 598 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncServiceMockTest); | 598 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncServiceMockTest); |
| 599 }; | 599 }; |
| 600 | 600 |
| 601 #if !defined(OS_ANDROID) | 601 #if !defined(OS_ANDROID) |
| 602 | 602 |
| 603 TEST_F(DriveFileSyncServiceMockTest, BatchSyncOnInitialization) { | |
| 604 const GURL kOrigin1 = ExtensionNameToGURL(FPL("example1")); | |
| 605 const GURL kOrigin2 = ExtensionNameToGURL(FPL("example2")); | |
| 606 const std::string kDirectoryResourceId1( | |
| 607 "folder:origin_directory_resource_id"); | |
| 608 const std::string kDirectoryResourceId2( | |
| 609 "folder:origin_directory_resource_id2"); | |
| 610 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); | |
| 611 | |
| 612 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); | |
| 613 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1); | |
| 614 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2); | |
| 615 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2); | |
| 616 | |
| 617 Sequence change_queue_seq; | |
| 618 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(0)) | |
| 619 .InSequence(change_queue_seq); | |
| 620 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(1)) | |
| 621 .Times(AnyNumber()) | |
| 622 .InSequence(change_queue_seq); | |
| 623 | |
| 624 SetUpDriveServiceExpectCallsForGetAboutResource(); | |
| 625 SetUpDriveServiceExpectCallsForGetResourceListInDirectory( | |
| 626 "chromeos/sync_file_system/listing_files_in_directory.json", | |
| 627 kDirectoryResourceId1); | |
| 628 | |
| 629 // The service will get called for incremental sync at the end after | |
| 630 // batch sync's done. | |
| 631 SetUpDriveServiceExpectCallsForIncrementalSync(); | |
| 632 | |
| 633 SetUpDriveSyncService(true); | |
| 634 message_loop()->RunUntilIdle(); | |
| 635 | |
| 636 // kOrigin1 should be a batch sync origin and kOrigin2 should be an | |
| 637 // incremental sync origin. | |
| 638 // 4 pending remote changes are from listing_files_in_directory as batch sync | |
| 639 // changes. | |
| 640 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); | |
| 641 EXPECT_EQ(1u, remote_change_handler().ChangesSize()); | |
| 642 } | |
| 643 | |
| 644 TEST_F(DriveFileSyncServiceMockTest, RegisterNewOrigin) { | 603 TEST_F(DriveFileSyncServiceMockTest, RegisterNewOrigin) { |
| 645 const GURL kOrigin("chrome-extension://example"); | 604 const GURL kOrigin("chrome-extension://example"); |
| 646 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); | 605 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); |
| 647 // The root id is in the "sync_root_entry.json" file. | 606 // The root id is in the "sync_root_entry.json" file. |
| 648 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); | 607 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); |
| 649 | 608 |
| 650 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); | 609 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); |
| 651 | 610 |
| 652 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(0)) | 611 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(0)) |
| 653 .Times(AnyNumber()); | 612 .Times(AnyNumber()); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 719 "chromeos/sync_file_system/listing_files_in_directory.json", | 678 "chromeos/sync_file_system/listing_files_in_directory.json", |
| 720 kDirectoryResourceId); | 679 kDirectoryResourceId); |
| 721 | 680 |
| 722 SetUpDriveSyncService(true); | 681 SetUpDriveSyncService(true); |
| 723 bool done = false; | 682 bool done = false; |
| 724 sync_service()->RegisterOriginForTrackingChanges( | 683 sync_service()->RegisterOriginForTrackingChanges( |
| 725 kOrigin, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK)); | 684 kOrigin, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK)); |
| 726 message_loop()->RunUntilIdle(); | 685 message_loop()->RunUntilIdle(); |
| 727 EXPECT_TRUE(done); | 686 EXPECT_TRUE(done); |
| 728 | 687 |
| 729 // The origin should be registered as a batch sync origin. | 688 // The origin should be registered as an incremental sync origin. |
| 730 VerifySizeOfRegisteredOrigins(1u, 0u, 0u); | 689 VerifySizeOfRegisteredOrigins(0u, 1u, 0u); |
| 731 | 690 |
| 732 // |listing_files_in_directory| contains 4 items to sync. | 691 // |listing_files_in_directory| contains 4 items to sync. |
| 733 EXPECT_EQ(1u, remote_change_handler().ChangesSize()); | 692 EXPECT_EQ(1u, remote_change_handler().ChangesSize()); |
| 734 } | 693 } |
| 735 | 694 |
| 736 TEST_F(DriveFileSyncServiceMockTest, UnregisterOrigin) { | 695 TEST_F(DriveFileSyncServiceMockTest, UnregisterOrigin) { |
| 737 const GURL kOrigin1 = ExtensionNameToGURL(FPL("example1")); | 696 const GURL kOrigin1 = ExtensionNameToGURL(FPL("example1")); |
| 738 const GURL kOrigin2 = ExtensionNameToGURL(FPL("example2")); | 697 const GURL kOrigin2 = ExtensionNameToGURL(FPL("example2")); |
| 739 const std::string kDirectoryResourceId1( | 698 const std::string kDirectoryResourceId1( |
| 740 "folder:origin_directory_resource_id"); | 699 "folder:origin_directory_resource_id"); |
| 741 const std::string kDirectoryResourceId2( | 700 const std::string kDirectoryResourceId2( |
| 742 "folder:origin_directory_resource_id2"); | 701 "folder:origin_directory_resource_id2"); |
| 743 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); | 702 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); |
| 744 | 703 |
| 745 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); | 704 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); |
| 746 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1); | 705 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1); |
| 747 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2); | 706 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2); |
| 748 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2); | 707 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2); |
| 749 | 708 |
| 750 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) | 709 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) |
| 751 .Times(AnyNumber()); | 710 .Times(AnyNumber()); |
| 752 | 711 |
| 753 InSequence sequence; | |
| 754 | |
| 755 SetUpDriveServiceExpectCallsForGetAboutResource(); | |
| 756 SetUpDriveServiceExpectCallsForGetResourceListInDirectory( | |
| 757 "chromeos/sync_file_system/listing_files_in_directory.json", | |
| 758 kDirectoryResourceId1); | |
| 759 | |
| 760 SetUpDriveServiceExpectCallsForIncrementalSync(); | |
| 761 | |
| 762 SetUpDriveSyncService(true); | 712 SetUpDriveSyncService(true); |
| 763 message_loop()->RunUntilIdle(); | 713 message_loop()->RunUntilIdle(); |
| 764 | 714 |
| 765 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); | 715 VerifySizeOfRegisteredOrigins(0u, 1u, 0u); |
| 766 EXPECT_EQ(1u, remote_change_handler().ChangesSize()); | 716 EXPECT_EQ(0u, remote_change_handler().ChangesSize()); |
| 767 | 717 |
| 768 bool done = false; | 718 bool done = false; |
| 769 sync_service()->UnregisterOriginForTrackingChanges( | 719 sync_service()->UnregisterOriginForTrackingChanges( |
| 770 kOrigin1, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK)); | 720 kOrigin1, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK)); |
| 771 message_loop()->RunUntilIdle(); | 721 message_loop()->RunUntilIdle(); |
| 772 EXPECT_TRUE(done); | 722 EXPECT_TRUE(done); |
| 773 | 723 |
| 774 VerifySizeOfRegisteredOrigins(0u, 1u, 0u); | 724 VerifySizeOfRegisteredOrigins(0u, 1u, 0u); |
| 775 EXPECT_TRUE(!remote_change_handler().HasChanges()); | 725 EXPECT_TRUE(!remote_change_handler().HasChanges()); |
| 776 } | 726 } |
| 777 | 727 |
| 778 TEST_F(DriveFileSyncServiceMockTest, UpdateRegisteredOrigins) { | 728 TEST_F(DriveFileSyncServiceMockTest, UpdateRegisteredOrigins) { |
| 779 const GURL kOrigin1 = ExtensionNameToGURL(FPL("example1")); | 729 const GURL kOrigin1 = ExtensionNameToGURL(FPL("example1")); |
| 780 const GURL kOrigin2 = ExtensionNameToGURL(FPL("example2")); | 730 const GURL kOrigin2 = ExtensionNameToGURL(FPL("example2")); |
| 781 const std::string kDirectoryResourceId1( | 731 const std::string kDirectoryResourceId1( |
| 782 "folder:origin_directory_resource_id"); | 732 "folder:origin_directory_resource_id"); |
| 783 const std::string kDirectoryResourceId2( | 733 const std::string kDirectoryResourceId2( |
| 784 "folder:origin_directory_resource_id2"); | 734 "folder:origin_directory_resource_id2"); |
| 785 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); | 735 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); |
| 786 const std::string extension_id1 = | 736 const std::string extension_id1 = |
| 787 extensions::id_util::GenerateIdForPath(base::FilePath(FPL("example1"))); | 737 extensions::id_util::GenerateIdForPath(base::FilePath(FPL("example1"))); |
| 788 const std::string extension_id2 = | 738 const std::string extension_id2 = |
| 789 extensions::id_util::GenerateIdForPath(base::FilePath(FPL("example2"))); | 739 extensions::id_util::GenerateIdForPath(base::FilePath(FPL("example2"))); |
| 790 | 740 |
| 791 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); | |
| 792 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1); | |
| 793 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2); | |
| 794 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2); | |
| 795 | |
| 796 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) | 741 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) |
| 797 .Times(AnyNumber()); | 742 .Times(AnyNumber()); |
| 798 | 743 |
| 799 InSequence sequence; | |
| 800 | |
| 801 SetUpDriveServiceExpectCallsForGetAboutResource(); | |
| 802 SetUpDriveServiceExpectCallsForGetResourceListInDirectory( | |
| 803 "chromeos/sync_file_system/listing_files_in_directory.json", | |
| 804 kDirectoryResourceId1); | |
| 805 | |
| 806 SetUpDriveServiceExpectCallsForIncrementalSync(); | |
| 807 | |
| 808 SetUpDriveSyncService(true); | 744 SetUpDriveSyncService(true); |
| 809 message_loop()->RunUntilIdle(); | 745 message_loop()->RunUntilIdle(); |
| 810 | 746 |
| 747 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); | |
| 748 pending_batch_sync_origins()->insert(std::make_pair( | |
| 749 kOrigin1, kDirectoryResourceId1)); | |
| 750 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2); | |
| 751 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2); | |
| 752 | |
| 811 // [1] Both extensions and origins are enabled. Nothing to do. | 753 // [1] Both extensions and origins are enabled. Nothing to do. |
| 812 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); | 754 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); |
| 813 UpdateRegisteredOrigins(); | 755 UpdateRegisteredOrigins(); |
| 814 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); | 756 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); |
| 815 | 757 |
| 816 DisableExtension(extension_id1); | 758 DisableExtension(extension_id1); |
| 817 DisableExtension(extension_id2); | 759 DisableExtension(extension_id2); |
| 818 | 760 |
| 819 // [2] Origins should be disabled since extensions were disabled. | 761 // [2] Origins should be disabled since extensions were disabled. |
| 762 // Note that pending batch sync origins that are disabled are dropped and | |
| 763 // do not get moved to disabled origin list. | |
| 820 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); | 764 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); |
| 821 UpdateRegisteredOrigins(); | 765 UpdateRegisteredOrigins(); |
| 822 VerifySizeOfRegisteredOrigins(0u, 0u, 2u); | 766 VerifySizeOfRegisteredOrigins(0u, 0u, 1u); |
| 823 | 767 |
| 824 // [3] Both extensions and origins are disabled. Nothing to do. | 768 // [3] Second origin remains disabled. Nothing to do. |
| 825 VerifySizeOfRegisteredOrigins(0u, 0u, 2u); | 769 VerifySizeOfRegisteredOrigins(0u, 0u, 1u); |
| 826 UpdateRegisteredOrigins(); | 770 UpdateRegisteredOrigins(); |
| 827 VerifySizeOfRegisteredOrigins(0u, 0u, 2u); | 771 VerifySizeOfRegisteredOrigins(0u, 0u, 1u); |
| 828 | 772 |
| 829 EnableExtension(extension_id1); | |
| 830 EnableExtension(extension_id2); | 773 EnableExtension(extension_id2); |
| 831 | 774 |
| 832 // [4] Origins should be re-enabled since extensions were re-enabled. | 775 // [4] Second extension should be re-enabled. |
| 833 VerifySizeOfRegisteredOrigins(0u, 0u, 2u); | 776 VerifySizeOfRegisteredOrigins(0u, 0u, 1u); |
| 834 UpdateRegisteredOrigins(); | 777 UpdateRegisteredOrigins(); |
| 835 VerifySizeOfRegisteredOrigins(2u, 0u, 0u); | 778 VerifySizeOfRegisteredOrigins(1u, 0u, 0u); |
| 836 | 779 |
| 780 // [5] Add back first extension as incremental sync so there's one of each. | |
| 781 EnableExtension(extension_id1); | |
| 782 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1); | |
| 783 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin1); | |
| 784 UpdateRegisteredOrigins(); | |
| 785 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); | |
| 786 | |
| 787 // Prepare for UninstallOrigin called by UpdateRegisteredOrigins that | |
| 788 // eventually kick off StartFetchChanges(). | |
| 789 SetUpDriveServiceExpectCallsForGetAboutResource(); | |
| 790 EXPECT_CALL(*mock_drive_service(), | |
| 791 DeleteResource(kDirectoryResourceId1, _, _)) | |
| 792 .WillOnce(InvokeEntryActionCallback(google_apis::HTTP_SUCCESS)); | |
| 793 UninstallExtension(extension_id1); | |
| 837 UninstallExtension(extension_id2); | 794 UninstallExtension(extension_id2); |
| 838 | 795 |
| 839 // Prepare for UninstallOrigin called by UpdateRegisteredOrigins. | 796 // [6] Uninstall both extensions. |
| 840 EXPECT_CALL(*mock_drive_service(), | 797 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); |
| 841 DeleteResource(kDirectoryResourceId2, _, _)) | |
| 842 .WillOnce(InvokeEntryActionCallback(google_apis::HTTP_SUCCESS)); | |
| 843 SetUpDriveServiceExpectCallsForGetAboutResource(); | |
| 844 SetUpDriveServiceExpectCallsForGetResourceListInDirectory( | |
| 845 "chromeos/sync_file_system/listing_files_in_directory.json", | |
| 846 kDirectoryResourceId1); | |
| 847 | |
| 848 // [5] |kOrigin2| should be unregistered since its extension was uninstalled. | |
| 849 VerifySizeOfRegisteredOrigins(2u, 0u, 0u); | |
| 850 UpdateRegisteredOrigins(); | 798 UpdateRegisteredOrigins(); |
| 851 VerifySizeOfRegisteredOrigins(1u, 0u, 0u); | 799 VerifySizeOfRegisteredOrigins(0u, 0u, 0u); |
| 852 } | 800 } |
| 853 | 801 |
| 854 TEST_F(DriveFileSyncServiceMockTest, RemoteChange_NoChange) { | 802 TEST_F(DriveFileSyncServiceMockTest, RemoteChange_NoChange) { |
| 855 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); | 803 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); |
| 856 | 804 |
| 857 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); | 805 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); |
| 858 | 806 |
| 859 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) | 807 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) |
| 860 .Times(AnyNumber()); | 808 .Times(AnyNumber()); |
| 861 | 809 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1021 | 969 |
| 1022 SetUpDriveSyncService(false); | 970 SetUpDriveSyncService(false); |
| 1023 bool done = false; | 971 bool done = false; |
| 1024 sync_service()->RegisterOriginForTrackingChanges( | 972 sync_service()->RegisterOriginForTrackingChanges( |
| 1025 kOrigin, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK)); | 973 kOrigin, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK)); |
| 1026 message_loop()->RunUntilIdle(); | 974 message_loop()->RunUntilIdle(); |
| 1027 EXPECT_TRUE(done); | 975 EXPECT_TRUE(done); |
| 1028 | 976 |
| 1029 // We must not have started batch sync for the newly registered origin, | 977 // We must not have started batch sync for the newly registered origin, |
| 1030 // so it should still be in the batch_sync_origins. | 978 // so it should still be in the batch_sync_origins. |
| 1031 VerifySizeOfRegisteredOrigins(1u, 0u, 0u); | 979 EXPECT_EQ(1u, pending_batch_sync_origins()->size()); |
| 1032 EXPECT_TRUE(!remote_change_handler().HasChanges()); | 980 EXPECT_TRUE(!remote_change_handler().HasChanges()); |
| 1033 } | 981 } |
| 1034 | 982 |
| 1035 TEST_F(DriveFileSyncServiceMockTest, RemoteChange_Override) { | 983 TEST_F(DriveFileSyncServiceMockTest, RemoteChange_Override) { |
| 1036 const GURL kOrigin = ExtensionNameToGURL(FPL("example1")); | 984 const GURL kOrigin = ExtensionNameToGURL(FPL("example1")); |
| 1037 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); | 985 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); |
| 1038 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); | 986 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); |
| 1039 const base::FilePath kFilePath(FPL("File 1.mp3")); | 987 const base::FilePath kFilePath(FPL("File 1.mp3")); |
| 1040 const std::string kFileResourceId("file:2_file_resource_id"); | 988 const std::string kFileResourceId("file:2_file_resource_id"); |
| 1041 const std::string kFileResourceId2("file:2_file_resource_id_2"); | 989 const std::string kFileResourceId2("file:2_file_resource_id_2"); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1116 entry->set_kind(google_apis::ENTRY_KIND_FOLDER); | 1064 entry->set_kind(google_apis::ENTRY_KIND_FOLDER); |
| 1117 | 1065 |
| 1118 // Expect to drop this change for file. | 1066 // Expect to drop this change for file. |
| 1119 EXPECT_FALSE(AppendIncrementalRemoteChangeByEntry( | 1067 EXPECT_FALSE(AppendIncrementalRemoteChangeByEntry( |
| 1120 kOrigin, *entry, 1)); | 1068 kOrigin, *entry, 1)); |
| 1121 } | 1069 } |
| 1122 | 1070 |
| 1123 #endif // !defined(OS_ANDROID) | 1071 #endif // !defined(OS_ANDROID) |
| 1124 | 1072 |
| 1125 } // namespace sync_file_system | 1073 } // namespace sync_file_system |
| OLD | NEW |