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

Side by Side Diff: chrome/browser/sync_file_system/drive_file_sync_service_mock_unittest.cc

Issue 15023022: Add to be fetched files instead of DriveMetadataStore.batch_sync_origins_ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added TODO about batch_sync_origin deprecation from DB. Created 7 years, 7 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 (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
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
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) {
96 EXPECT_FALSE(*done); 93 EXPECT_FALSE(*done);
97 *done = true; 94 *done = true;
98 EXPECT_EQ(expected, actual); 95 EXPECT_EQ(expected, actual);
99 } 96 }
100 97
98 void ExpectOkStatus(SyncStatusCode status) {
99 EXPECT_EQ(SYNC_STATUS_OK, status);
100 }
101
101 // Mocks adding an installed extension to ExtensionService. 102 // Mocks adding an installed extension to ExtensionService.
102 scoped_refptr<const extensions::Extension> AddTestExtension( 103 scoped_refptr<const extensions::Extension> AddTestExtension(
103 ExtensionService* extension_service, 104 ExtensionService* extension_service,
104 const base::FilePath::StringType& extension_name) { 105 const base::FilePath::StringType& extension_name) {
105 std::string id = extensions::id_util::GenerateIdForPath( 106 std::string id = extensions::id_util::GenerateIdForPath(
106 base::FilePath(extension_name)); 107 base::FilePath(extension_name));
107 108
108 scoped_refptr<const Extension> extension = 109 scoped_refptr<const Extension> extension =
109 extensions::ExtensionBuilder().SetManifest( 110 extensions::ExtensionBuilder().SetManifest(
110 DictionaryBuilder() 111 DictionaryBuilder()
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 extension_service_->UnloadExtension( 343 extension_service_->UnloadExtension(
343 extension_id, extension_misc::UNLOAD_REASON_UNINSTALL); 344 extension_id, extension_misc::UNLOAD_REASON_UNINSTALL);
344 } 345 }
345 346
346 void UpdateRegisteredOrigins() { 347 void UpdateRegisteredOrigins() {
347 sync_service_->UpdateRegisteredOrigins(); 348 sync_service_->UpdateRegisteredOrigins();
348 // Wait for completion of uninstalling origin. 349 // Wait for completion of uninstalling origin.
349 message_loop()->RunUntilIdle(); 350 message_loop()->RunUntilIdle();
350 } 351 }
351 352
352 void VerifySizeOfRegisteredOrigins( 353 void VerifySizeOfRegisteredOrigins(size_t b_size,
353 DriveMetadataStore::ResourceIdByOrigin::size_type b_size, 354 size_t i_size,
354 DriveMetadataStore::ResourceIdByOrigin::size_type i_size, 355 size_t d_size) {
355 DriveMetadataStore::ResourceIdByOrigin::size_type d_size) { 356 EXPECT_EQ(b_size, pending_batch_sync_origins()->size());
356 EXPECT_EQ(b_size, metadata_store()->batch_sync_origins().size());
357 EXPECT_EQ(i_size, metadata_store()->incremental_sync_origins().size()); 357 EXPECT_EQ(i_size, metadata_store()->incremental_sync_origins().size());
358 EXPECT_EQ(d_size, metadata_store()->disabled_origins().size()); 358 EXPECT_EQ(d_size, metadata_store()->disabled_origins().size());
359 } 359 }
360 360
361 drive::APIUtilInterface* api_util() { 361 drive::APIUtilInterface* api_util() {
362 if (api_util_) 362 if (api_util_)
363 return api_util_.get(); 363 return api_util_.get();
364 return sync_service_->api_util_.get(); 364 return sync_service_->api_util_.get();
365 } 365 }
366 366
(...skipping 14 matching lines...) Expand all
381 StrictMock<MockFileStatusObserver>* mock_file_status_observer() { 381 StrictMock<MockFileStatusObserver>* mock_file_status_observer() {
382 return &mock_file_status_observer_; 382 return &mock_file_status_observer_;
383 } 383 }
384 384
385 StrictMock<MockRemoteChangeProcessor>* mock_remote_processor() { 385 StrictMock<MockRemoteChangeProcessor>* mock_remote_processor() {
386 return &mock_remote_processor_; 386 return &mock_remote_processor_;
387 } 387 }
388 388
389 MessageLoop* message_loop() { return &message_loop_; } 389 MessageLoop* message_loop() { return &message_loop_; }
390 DriveFileSyncService* sync_service() { return sync_service_.get(); } 390 DriveFileSyncService* sync_service() { return sync_service_.get(); }
391 std::map<GURL, std::string>* pending_batch_sync_origins() {
392 return &(sync_service()->pending_batch_sync_origins_);
393 }
391 394
392 const RemoteChangeHandler& remote_change_handler() const { 395 const RemoteChangeHandler& remote_change_handler() const {
393 return sync_service_->remote_change_handler_; 396 return sync_service_->remote_change_handler_;
394 } 397 }
395 398
396 fileapi::FileSystemURL CreateURL(const GURL& origin, 399 fileapi::FileSystemURL CreateURL(const GURL& origin,
397 const base::FilePath::StringType& path) { 400 const base::FilePath::StringType& path) {
398 return CreateSyncableFileSystemURL( 401 return CreateSyncableFileSystemURL(
399 origin, kServiceName, base::FilePath(path)); 402 origin, kServiceName, base::FilePath(path));
400 } 403 }
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 StrictMock<MockRemoteChangeProcessor> mock_remote_processor_; 596 StrictMock<MockRemoteChangeProcessor> mock_remote_processor_;
594 597
595 scoped_ptr<drive::APIUtil> api_util_; 598 scoped_ptr<drive::APIUtil> api_util_;
596 scoped_ptr<DriveMetadataStore> metadata_store_; 599 scoped_ptr<DriveMetadataStore> metadata_store_;
597 600
598 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncServiceMockTest); 601 DISALLOW_COPY_AND_ASSIGN(DriveFileSyncServiceMockTest);
599 }; 602 };
600 603
601 #if !defined(OS_ANDROID) 604 #if !defined(OS_ANDROID)
602 605
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) { 606 TEST_F(DriveFileSyncServiceMockTest, RegisterNewOrigin) {
645 const GURL kOrigin("chrome-extension://example"); 607 const GURL kOrigin("chrome-extension://example");
646 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); 608 const std::string kDirectoryResourceId("folder:origin_directory_resource_id");
647 // The root id is in the "sync_root_entry.json" file. 609 // The root id is in the "sync_root_entry.json" file.
648 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); 610 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
649 611
650 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); 612 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId);
651 613
652 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(0)) 614 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(0))
653 .Times(AnyNumber()); 615 .Times(AnyNumber());
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 "chromeos/sync_file_system/listing_files_in_directory.json", 681 "chromeos/sync_file_system/listing_files_in_directory.json",
720 kDirectoryResourceId); 682 kDirectoryResourceId);
721 683
722 SetUpDriveSyncService(true); 684 SetUpDriveSyncService(true);
723 bool done = false; 685 bool done = false;
724 sync_service()->RegisterOriginForTrackingChanges( 686 sync_service()->RegisterOriginForTrackingChanges(
725 kOrigin, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK)); 687 kOrigin, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK));
726 message_loop()->RunUntilIdle(); 688 message_loop()->RunUntilIdle();
727 EXPECT_TRUE(done); 689 EXPECT_TRUE(done);
728 690
729 // The origin should be registered as a batch sync origin. 691 // The origin should be registered as an incremental sync origin.
730 VerifySizeOfRegisteredOrigins(1u, 0u, 0u); 692 VerifySizeOfRegisteredOrigins(0u, 1u, 0u);
731 693
732 // |listing_files_in_directory| contains 4 items to sync. 694 // |listing_files_in_directory| contains 4 items to sync.
733 EXPECT_EQ(1u, remote_change_handler().ChangesSize()); 695 EXPECT_EQ(1u, remote_change_handler().ChangesSize());
734 } 696 }
735 697
736 TEST_F(DriveFileSyncServiceMockTest, UnregisterOrigin) { 698 TEST_F(DriveFileSyncServiceMockTest, UnregisterOrigin) {
737 const GURL kOrigin1 = ExtensionNameToGURL(FPL("example1")); 699 const GURL kOrigin1 = ExtensionNameToGURL(FPL("example1"));
738 const GURL kOrigin2 = ExtensionNameToGURL(FPL("example2")); 700 const GURL kOrigin2 = ExtensionNameToGURL(FPL("example2"));
739 const std::string kDirectoryResourceId1( 701 const std::string kDirectoryResourceId1(
740 "folder:origin_directory_resource_id"); 702 "folder:origin_directory_resource_id");
741 const std::string kDirectoryResourceId2( 703 const std::string kDirectoryResourceId2(
742 "folder:origin_directory_resource_id2"); 704 "folder:origin_directory_resource_id2");
743 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); 705 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
744 706
745 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); 707 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId);
746 metadata_store()->AddBatchSyncOrigin(kOrigin1, kDirectoryResourceId1); 708 metadata_store()->AddIncrementalSyncOrigin(kOrigin1, kDirectoryResourceId1);
747 metadata_store()->AddBatchSyncOrigin(kOrigin2, kDirectoryResourceId2); 709 metadata_store()->AddIncrementalSyncOrigin(kOrigin2, kDirectoryResourceId2);
748 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin2);
749 710
750 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) 711 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_))
751 .Times(AnyNumber()); 712 .Times(AnyNumber());
752 713
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); 714 SetUpDriveSyncService(true);
763 message_loop()->RunUntilIdle(); 715 message_loop()->RunUntilIdle();
764 716
765 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); 717 VerifySizeOfRegisteredOrigins(0u, 2u, 0u);
766 EXPECT_EQ(1u, remote_change_handler().ChangesSize()); 718 EXPECT_EQ(0u, remote_change_handler().ChangesSize());
767 719
768 bool done = false; 720 bool done = false;
769 sync_service()->UnregisterOriginForTrackingChanges( 721 sync_service()->UnregisterOriginForTrackingChanges(
770 kOrigin1, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK)); 722 kOrigin1, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK));
771 message_loop()->RunUntilIdle(); 723 message_loop()->RunUntilIdle();
772 EXPECT_TRUE(done); 724 EXPECT_TRUE(done);
773 725
774 VerifySizeOfRegisteredOrigins(0u, 1u, 0u); 726 VerifySizeOfRegisteredOrigins(0u, 1u, 0u);
775 EXPECT_TRUE(!remote_change_handler().HasChanges()); 727 EXPECT_TRUE(!remote_change_handler().HasChanges());
776 } 728 }
777 729
778 TEST_F(DriveFileSyncServiceMockTest, UpdateRegisteredOrigins) { 730 TEST_F(DriveFileSyncServiceMockTest, UpdateRegisteredOrigins) {
779 const GURL kOrigin1 = ExtensionNameToGURL(FPL("example1")); 731 const GURL kOrigin1 = ExtensionNameToGURL(FPL("example1"));
780 const GURL kOrigin2 = ExtensionNameToGURL(FPL("example2")); 732 const GURL kOrigin2 = ExtensionNameToGURL(FPL("example2"));
781 const std::string kDirectoryResourceId1( 733 const std::string kDirectoryResourceId1(
782 "folder:origin_directory_resource_id"); 734 "folder:origin_directory_resource_id");
783 const std::string kDirectoryResourceId2( 735 const std::string kDirectoryResourceId2(
784 "folder:origin_directory_resource_id2"); 736 "folder:origin_directory_resource_id2");
785 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); 737 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
786 const std::string extension_id1 = 738 const std::string extension_id1 =
787 extensions::id_util::GenerateIdForPath(base::FilePath(FPL("example1"))); 739 extensions::id_util::GenerateIdForPath(base::FilePath(FPL("example1")));
788 const std::string extension_id2 = 740 const std::string extension_id2 =
789 extensions::id_util::GenerateIdForPath(base::FilePath(FPL("example2"))); 741 extensions::id_util::GenerateIdForPath(base::FilePath(FPL("example2")));
790 742
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(_)) 743 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_))
797 .Times(AnyNumber()); 744 .Times(AnyNumber());
798 745
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); 746 SetUpDriveSyncService(true);
809 message_loop()->RunUntilIdle(); 747 message_loop()->RunUntilIdle();
810 748
749 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId);
750 metadata_store()->AddIncrementalSyncOrigin(kOrigin1, kDirectoryResourceId1);
751 metadata_store()->AddIncrementalSyncOrigin(kOrigin2, kDirectoryResourceId2);
tzik 2013/05/23 04:03:05 Could you move this back before SetUpDriveSyncServ
calvinlo 2013/05/23 08:23:04 Done.
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(0u, 2u, 0u);
813 UpdateRegisteredOrigins(); 755 UpdateRegisteredOrigins();
814 VerifySizeOfRegisteredOrigins(1u, 1u, 0u); 756 VerifySizeOfRegisteredOrigins(0u, 2u, 0u);
815 757
758 // [2] Extension 1 should move to disabled list.
816 DisableExtension(extension_id1); 759 DisableExtension(extension_id1);
817 DisableExtension(extension_id2); 760 UpdateRegisteredOrigins();
761 VerifySizeOfRegisteredOrigins(0u, 1u, 1u);
818 762
819 // [2] Origins should be disabled since extensions were disabled. 763 // [3] Make sure that state remains the same, nothing should change.
820 VerifySizeOfRegisteredOrigins(1u, 1u, 0u);
821 UpdateRegisteredOrigins(); 764 UpdateRegisteredOrigins();
822 VerifySizeOfRegisteredOrigins(0u, 0u, 2u); 765 VerifySizeOfRegisteredOrigins(0u, 1u, 1u);
823 766
824 // [3] Both extensions and origins are disabled. Nothing to do. 767 // [4] Uninstall Extension 2.
825 VerifySizeOfRegisteredOrigins(0u, 0u, 2u); 768 UninstallExtension(extension_id2);
826 UpdateRegisteredOrigins(); 769 UpdateRegisteredOrigins();
827 VerifySizeOfRegisteredOrigins(0u, 0u, 2u); 770 VerifySizeOfRegisteredOrigins(0u, 0u, 1u);
828 771
772 // [5] Re-enable Extension 1. It moves back to batch and not to incremental.
829 EnableExtension(extension_id1); 773 EnableExtension(extension_id1);
830 EnableExtension(extension_id2);
831
832 // [4] Origins should be re-enabled since extensions were re-enabled.
833 VerifySizeOfRegisteredOrigins(0u, 0u, 2u);
834 UpdateRegisteredOrigins();
835 VerifySizeOfRegisteredOrigins(2u, 0u, 0u);
836
837 UninstallExtension(extension_id2);
838
839 // Prepare for UninstallOrigin called by UpdateRegisteredOrigins.
840 EXPECT_CALL(*mock_drive_service(),
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(); 774 UpdateRegisteredOrigins();
851 VerifySizeOfRegisteredOrigins(1u, 0u, 0u); 775 VerifySizeOfRegisteredOrigins(1u, 0u, 0u);
852 } 776 }
853 777
854 TEST_F(DriveFileSyncServiceMockTest, RemoteChange_NoChange) { 778 TEST_F(DriveFileSyncServiceMockTest, RemoteChange_NoChange) {
855 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); 779 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
856 780
857 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); 781 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId);
858 782
859 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) 783 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_))
(...skipping 10 matching lines...) Expand all
870 EXPECT_TRUE(!remote_change_handler().HasChanges()); 794 EXPECT_TRUE(!remote_change_handler().HasChanges());
871 } 795 }
872 796
873 TEST_F(DriveFileSyncServiceMockTest, RemoteChange_Busy) { 797 TEST_F(DriveFileSyncServiceMockTest, RemoteChange_Busy) {
874 const GURL kOrigin = ExtensionNameToGURL(FPL("example1")); 798 const GURL kOrigin = ExtensionNameToGURL(FPL("example1"));
875 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); 799 const std::string kDirectoryResourceId("folder:origin_directory_resource_id");
876 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); 800 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
877 const base::FilePath::StringType kFileName(FPL("File 1.mp3")); 801 const base::FilePath::StringType kFileName(FPL("File 1.mp3"));
878 802
879 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); 803 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId);
880 metadata_store()->AddBatchSyncOrigin(kOrigin, kDirectoryResourceId); 804 metadata_store()->AddIncrementalSyncOrigin(kOrigin, kDirectoryResourceId);
881 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin);
882 805
883 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) 806 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_))
884 .Times(AnyNumber()); 807 .Times(AnyNumber());
885 808
886 EXPECT_CALL(*mock_remote_processor(), 809 EXPECT_CALL(*mock_remote_processor(),
887 PrepareForProcessRemoteChange(CreateURL(kOrigin, kFileName), 810 PrepareForProcessRemoteChange(CreateURL(kOrigin, kFileName),
888 kServiceName, _)) 811 kServiceName, _))
889 .WillOnce(PrepareForRemoteChange_Busy()); 812 .WillOnce(PrepareForRemoteChange_Busy());
890 EXPECT_CALL(*mock_remote_processor(), 813 EXPECT_CALL(*mock_remote_processor(),
891 ClearLocalChanges(CreateURL(kOrigin, kFileName), _)) 814 ClearLocalChanges(CreateURL(kOrigin, kFileName), _))
(...skipping 15 matching lines...) Expand all
907 } 830 }
908 831
909 TEST_F(DriveFileSyncServiceMockTest, RemoteChange_NewFile) { 832 TEST_F(DriveFileSyncServiceMockTest, RemoteChange_NewFile) {
910 const GURL kOrigin = ExtensionNameToGURL(FPL("example1")); 833 const GURL kOrigin = ExtensionNameToGURL(FPL("example1"));
911 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); 834 const std::string kDirectoryResourceId("folder:origin_directory_resource_id");
912 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); 835 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
913 const base::FilePath::StringType kFileName(FPL("File 1.mp3")); 836 const base::FilePath::StringType kFileName(FPL("File 1.mp3"));
914 const std::string kFileResourceId("file:2_file_resource_id"); 837 const std::string kFileResourceId("file:2_file_resource_id");
915 838
916 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); 839 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId);
917 metadata_store()->AddBatchSyncOrigin(kOrigin, kDirectoryResourceId); 840 metadata_store()->AddIncrementalSyncOrigin(kOrigin, kDirectoryResourceId);
918 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin);
919 841
920 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) 842 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_))
921 .Times(AnyNumber()); 843 .Times(AnyNumber());
922 844
923 EXPECT_CALL(*mock_remote_processor(), 845 EXPECT_CALL(*mock_remote_processor(),
924 PrepareForProcessRemoteChange(CreateURL(kOrigin, kFileName), 846 PrepareForProcessRemoteChange(CreateURL(kOrigin, kFileName),
925 kServiceName, _)) 847 kServiceName, _))
926 .WillOnce(PrepareForRemoteChange_NotFound()); 848 .WillOnce(PrepareForRemoteChange_NotFound());
927 EXPECT_CALL(*mock_remote_processor(), 849 EXPECT_CALL(*mock_remote_processor(),
928 ClearLocalChanges(CreateURL(kOrigin, kFileName), _)) 850 ClearLocalChanges(CreateURL(kOrigin, kFileName), _))
(...skipping 21 matching lines...) Expand all
950 } 872 }
951 873
952 TEST_F(DriveFileSyncServiceMockTest, RemoteChange_UpdateFile) { 874 TEST_F(DriveFileSyncServiceMockTest, RemoteChange_UpdateFile) {
953 const GURL kOrigin = ExtensionNameToGURL(FPL("example1")); 875 const GURL kOrigin = ExtensionNameToGURL(FPL("example1"));
954 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); 876 const std::string kDirectoryResourceId("folder:origin_directory_resource_id");
955 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); 877 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
956 const base::FilePath::StringType kFileName(FPL("File 1.mp3")); 878 const base::FilePath::StringType kFileName(FPL("File 1.mp3"));
957 const std::string kFileResourceId("file:2_file_resource_id"); 879 const std::string kFileResourceId("file:2_file_resource_id");
958 880
959 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); 881 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId);
960 metadata_store()->AddBatchSyncOrigin(kOrigin, kDirectoryResourceId); 882 metadata_store()->AddIncrementalSyncOrigin(kOrigin, kDirectoryResourceId);
961 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin);
962 883
963 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) 884 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_))
964 .Times(AnyNumber()); 885 .Times(AnyNumber());
965 886
966 EXPECT_CALL(*mock_remote_processor(), 887 EXPECT_CALL(*mock_remote_processor(),
967 PrepareForProcessRemoteChange(CreateURL(kOrigin, kFileName), 888 PrepareForProcessRemoteChange(CreateURL(kOrigin, kFileName),
968 kServiceName, _)) 889 kServiceName, _))
969 .WillOnce(PrepareForRemoteChange_NotModified()); 890 .WillOnce(PrepareForRemoteChange_NotModified());
970 EXPECT_CALL(*mock_remote_processor(), 891 EXPECT_CALL(*mock_remote_processor(),
971 ClearLocalChanges(CreateURL(kOrigin, kFileName), _)) 892 ClearLocalChanges(CreateURL(kOrigin, kFileName), _))
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 942
1022 SetUpDriveSyncService(false); 943 SetUpDriveSyncService(false);
1023 bool done = false; 944 bool done = false;
1024 sync_service()->RegisterOriginForTrackingChanges( 945 sync_service()->RegisterOriginForTrackingChanges(
1025 kOrigin, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK)); 946 kOrigin, base::Bind(&ExpectEqStatus, &done, SYNC_STATUS_OK));
1026 message_loop()->RunUntilIdle(); 947 message_loop()->RunUntilIdle();
1027 EXPECT_TRUE(done); 948 EXPECT_TRUE(done);
1028 949
1029 // We must not have started batch sync for the newly registered origin, 950 // We must not have started batch sync for the newly registered origin,
1030 // so it should still be in the batch_sync_origins. 951 // so it should still be in the batch_sync_origins.
1031 VerifySizeOfRegisteredOrigins(1u, 0u, 0u); 952 EXPECT_EQ(1u, pending_batch_sync_origins()->size());
tzik 2013/05/23 04:03:05 Can we revert this?
calvinlo 2013/05/23 08:23:04 Done.
1032 EXPECT_TRUE(!remote_change_handler().HasChanges()); 953 EXPECT_TRUE(!remote_change_handler().HasChanges());
1033 } 954 }
1034 955
1035 TEST_F(DriveFileSyncServiceMockTest, RemoteChange_Override) { 956 TEST_F(DriveFileSyncServiceMockTest, RemoteChange_Override) {
1036 const GURL kOrigin = ExtensionNameToGURL(FPL("example1")); 957 const GURL kOrigin = ExtensionNameToGURL(FPL("example1"));
1037 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); 958 const std::string kDirectoryResourceId("folder:origin_directory_resource_id");
1038 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); 959 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
1039 const base::FilePath kFilePath(FPL("File 1.mp3")); 960 const base::FilePath kFilePath(FPL("File 1.mp3"));
1040 const std::string kFileResourceId("file:2_file_resource_id"); 961 const std::string kFileResourceId("file:2_file_resource_id");
1041 const std::string kFileResourceId2("file:2_file_resource_id_2"); 962 const std::string kFileResourceId2("file:2_file_resource_id_2");
1042 const fileapi::FileSystemURL kURL(CreateURL(kOrigin, kFilePath.value())); 963 const fileapi::FileSystemURL kURL(CreateURL(kOrigin, kFilePath.value()));
1043 964
1044 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); 965 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId);
1045 metadata_store()->AddBatchSyncOrigin(kOrigin, kDirectoryResourceId); 966 metadata_store()->AddIncrementalSyncOrigin(kOrigin, kDirectoryResourceId);
1046 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin);
1047 967
1048 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) 968 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_))
1049 .Times(AnyNumber()); 969 .Times(AnyNumber());
1050 970
1051 SetUpDriveSyncService(true); 971 SetUpDriveSyncService(true);
1052 972
1053 EXPECT_TRUE(AppendIncrementalRemoteChange( 973 EXPECT_TRUE(AppendIncrementalRemoteChange(
1054 kOrigin, kFilePath, false /* is_deleted */, 974 kOrigin, kFilePath, false /* is_deleted */,
1055 kFileResourceId, 2, "remote_file_md5")); 975 kFileResourceId, 2, "remote_file_md5"));
1056 976
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 kOrigin, kFilePath, false /* is_deleted */, 1016 kOrigin, kFilePath, false /* is_deleted */,
1097 kFileResourceId2, 8, "updated_file_md5")); 1017 kFileResourceId2, 8, "updated_file_md5"));
1098 } 1018 }
1099 1019
1100 TEST_F(DriveFileSyncServiceMockTest, RemoteChange_Folder) { 1020 TEST_F(DriveFileSyncServiceMockTest, RemoteChange_Folder) {
1101 const GURL kOrigin = ExtensionNameToGURL(FPL("example1")); 1021 const GURL kOrigin = ExtensionNameToGURL(FPL("example1"));
1102 const std::string kDirectoryResourceId("folder:origin_directory_resource_id"); 1022 const std::string kDirectoryResourceId("folder:origin_directory_resource_id");
1103 const std::string kSyncRootResourceId("folder:sync_root_resource_id"); 1023 const std::string kSyncRootResourceId("folder:sync_root_resource_id");
1104 1024
1105 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId); 1025 metadata_store()->SetSyncRootDirectory(kSyncRootResourceId);
1106 metadata_store()->AddBatchSyncOrigin(kOrigin, kDirectoryResourceId); 1026 metadata_store()->AddIncrementalSyncOrigin(kOrigin, kDirectoryResourceId);
1107 metadata_store()->MoveBatchSyncOriginToIncremental(kOrigin);
1108 1027
1109 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_)) 1028 EXPECT_CALL(*mock_remote_observer(), OnRemoteChangeQueueUpdated(_))
1110 .Times(AnyNumber()); 1029 .Times(AnyNumber());
1111 1030
1112 SetUpDriveSyncService(true); 1031 SetUpDriveSyncService(true);
1113 1032
1114 scoped_ptr<ResourceEntry> entry(ResourceEntry::ExtractAndParse( 1033 scoped_ptr<ResourceEntry> entry(ResourceEntry::ExtractAndParse(
1115 *LoadJSONFile("chromeos/gdata/file_entry.json"))); 1034 *LoadJSONFile("chromeos/gdata/file_entry.json")));
1116 entry->set_kind(google_apis::ENTRY_KIND_FOLDER); 1035 entry->set_kind(google_apis::ENTRY_KIND_FOLDER);
1117 1036
1118 // Expect to drop this change for file. 1037 // Expect to drop this change for file.
1119 EXPECT_FALSE(AppendIncrementalRemoteChangeByEntry( 1038 EXPECT_FALSE(AppendIncrementalRemoteChangeByEntry(
1120 kOrigin, *entry, 1)); 1039 kOrigin, *entry, 1));
1121 } 1040 }
1122 1041
1123 #endif // !defined(OS_ANDROID) 1042 #endif // !defined(OS_ANDROID)
1124 1043
1125 } // namespace sync_file_system 1044 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698