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

Side by Side Diff: sync/internal_api/sync_manager_impl_unittest.cc

Issue 68483005: ProfileSyncServiceTest refactoring (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix mac build Created 7 years, 1 month 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
« no previous file with comments | « chrome/browser/sync/profile_sync_service_unittest.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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 // Unit tests for the SyncApi. Note that a lot of the underlying 5 // Unit tests for the SyncApi. Note that a lot of the underlying
6 // functionality is provided by the Syncable layer, which has its own 6 // functionality is provided by the Syncable layer, which has its own
7 // unit tests. We'll test SyncApi specific things in this harness. 7 // unit tests. We'll test SyncApi specific things in this harness.
8 8
9 #include <cstddef> 9 #include <cstddef>
10 #include <map> 10 #include <map>
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 800 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
801 801
802 extensions_activity_ = new ExtensionsActivity(); 802 extensions_activity_ = new ExtensionsActivity();
803 803
804 SyncCredentials credentials; 804 SyncCredentials credentials;
805 credentials.email = "foo@bar.com"; 805 credentials.email = "foo@bar.com";
806 credentials.sync_token = "sometoken"; 806 credentials.sync_token = "sometoken";
807 807
808 sync_manager_.AddObserver(&manager_observer_); 808 sync_manager_.AddObserver(&manager_observer_);
809 EXPECT_CALL(manager_observer_, OnInitializationComplete(_, _, _, _)). 809 EXPECT_CALL(manager_observer_, OnInitializationComplete(_, _, _, _)).
810 WillOnce(SaveArg<0>(&js_backend_)); 810 WillOnce(DoAll(SaveArg<0>(&js_backend_),
811 SaveArg<2>(&initialization_succeeded_)));
811 812
812 EXPECT_FALSE(js_backend_.IsInitialized()); 813 EXPECT_FALSE(js_backend_.IsInitialized());
813 814
814 std::vector<ModelSafeWorker*> workers; 815 std::vector<ModelSafeWorker*> workers;
815 ModelSafeRoutingInfo routing_info; 816 ModelSafeRoutingInfo routing_info;
816 GetModelSafeRoutingInfo(&routing_info); 817 GetModelSafeRoutingInfo(&routing_info);
817 818
818 // Takes ownership of |fake_invalidator_|. 819 // Takes ownership of |fake_invalidator_|.
819 sync_manager_.Init( 820 sync_manager_.Init(
820 temp_dir_.path(), 821 temp_dir_.path(),
(...skipping 13 matching lines...) Expand all
834 &encryptor_, 835 &encryptor_,
835 scoped_ptr<UnrecoverableErrorHandler>( 836 scoped_ptr<UnrecoverableErrorHandler>(
836 new TestUnrecoverableErrorHandler).Pass(), 837 new TestUnrecoverableErrorHandler).Pass(),
837 NULL, 838 NULL,
838 &cancelation_signal_); 839 &cancelation_signal_);
839 840
840 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); 841 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_);
841 842
842 EXPECT_TRUE(js_backend_.IsInitialized()); 843 EXPECT_TRUE(js_backend_.IsInitialized());
843 844
844 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); 845 if (initialization_succeeded_) {
845 i != routing_info.end(); ++i) { 846 for (ModelSafeRoutingInfo::iterator i = routing_info.begin();
846 type_roots_[i->first] = MakeServerNodeForType( 847 i != routing_info.end(); ++i) {
847 sync_manager_.GetUserShare(), i->first); 848 type_roots_[i->first] = MakeServerNodeForType(
849 sync_manager_.GetUserShare(), i->first);
850 }
848 } 851 }
849 PumpLoop(); 852 PumpLoop();
850 } 853 }
851 854
852 void TearDown() { 855 void TearDown() {
853 sync_manager_.RemoveObserver(&manager_observer_); 856 sync_manager_.RemoveObserver(&manager_observer_);
854 sync_manager_.ShutdownOnSyncThread(); 857 sync_manager_.ShutdownOnSyncThread();
855 PumpLoop(); 858 PumpLoop();
856 } 859 }
857 860
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 base::ScopedTempDir temp_dir_; 1014 base::ScopedTempDir temp_dir_;
1012 // Sync Id's for the roots of the enabled datatypes. 1015 // Sync Id's for the roots of the enabled datatypes.
1013 std::map<ModelType, int64> type_roots_; 1016 std::map<ModelType, int64> type_roots_;
1014 scoped_refptr<ExtensionsActivity> extensions_activity_; 1017 scoped_refptr<ExtensionsActivity> extensions_activity_;
1015 1018
1016 protected: 1019 protected:
1017 FakeEncryptor encryptor_; 1020 FakeEncryptor encryptor_;
1018 SyncManagerImpl sync_manager_; 1021 SyncManagerImpl sync_manager_;
1019 CancelationSignal cancelation_signal_; 1022 CancelationSignal cancelation_signal_;
1020 WeakHandle<JsBackend> js_backend_; 1023 WeakHandle<JsBackend> js_backend_;
1024 bool initialization_succeeded_;
1021 StrictMock<SyncManagerObserverMock> manager_observer_; 1025 StrictMock<SyncManagerObserverMock> manager_observer_;
1022 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; 1026 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_;
1023 InternalComponentsFactory::Switches switches_; 1027 InternalComponentsFactory::Switches switches_;
1024 }; 1028 };
1025 1029
1026 TEST_F(SyncManagerTest, ProcessJsMessage) { 1030 TEST_F(SyncManagerTest, ProcessJsMessage) {
1027 const JsArgList kNoArgs; 1031 const JsArgList kNoArgs;
1028 1032
1029 StrictMock<MockJsReplyHandler> reply_handler; 1033 StrictMock<MockJsReplyHandler> reply_handler;
1030 1034
(...skipping 2444 matching lines...) Expand 10 before | Expand all | Expand 10 after
3475 FindChangeInList(folder_a_id, ChangeRecord::ACTION_UPDATE); 3479 FindChangeInList(folder_a_id, ChangeRecord::ACTION_UPDATE);
3476 size_t folder_b_pos = 3480 size_t folder_b_pos =
3477 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE); 3481 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE);
3478 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE); 3482 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE);
3479 3483
3480 // Deletes should appear before updates. 3484 // Deletes should appear before updates.
3481 EXPECT_LT(child_pos, folder_a_pos); 3485 EXPECT_LT(child_pos, folder_a_pos);
3482 EXPECT_LT(folder_b_pos, folder_a_pos); 3486 EXPECT_LT(folder_b_pos, folder_a_pos);
3483 } 3487 }
3484 3488
3489 // During initialization SyncManagerImpl loads sqlite database. If it fails to
3490 // do so it should fail initialization. This test verifies this behavior.
3491 // Test reuses SyncManagerImpl initialization from SyncManagerTest but overrides
3492 // InternalComponentsFactory to return DirectoryBackingStore that always fails
3493 // to load.
3494 class SyncManagerInitInvalidStorageTest : public SyncManagerTest {
3495 public:
3496 SyncManagerInitInvalidStorageTest() {
3497 }
3498
3499 virtual InternalComponentsFactory* GetFactory() OVERRIDE {
3500 return new TestInternalComponentsFactory(GetSwitches(), STORAGE_INVALID);
3501 }
3502 };
3503
3504 // SyncManagerInitInvalidStorageTest::GetFactory will return
3505 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails.
3506 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's
3507 // task is to ensure that SyncManagerImpl reported initialization failure in
3508 // OnInitializationComplete callback.
3509 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) {
3510 EXPECT_FALSE(initialization_succeeded_);
3511 }
3512
3485 } // namespace 3513 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698