| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 2476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3507 FindChangeInList(folder_a_id, ChangeRecord::ACTION_UPDATE); | 3511 FindChangeInList(folder_a_id, ChangeRecord::ACTION_UPDATE); |
| 3508 size_t folder_b_pos = | 3512 size_t folder_b_pos = |
| 3509 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE); | 3513 FindChangeInList(folder_b_id, ChangeRecord::ACTION_DELETE); |
| 3510 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE); | 3514 size_t child_pos = FindChangeInList(child_id, ChangeRecord::ACTION_DELETE); |
| 3511 | 3515 |
| 3512 // Deletes should appear before updates. | 3516 // Deletes should appear before updates. |
| 3513 EXPECT_LT(child_pos, folder_a_pos); | 3517 EXPECT_LT(child_pos, folder_a_pos); |
| 3514 EXPECT_LT(folder_b_pos, folder_a_pos); | 3518 EXPECT_LT(folder_b_pos, folder_a_pos); |
| 3515 } | 3519 } |
| 3516 | 3520 |
| 3521 // During initialization SyncManagerImpl loads sqlite database. If it fails to |
| 3522 // do so it should fail initialization. This test verifies this behavior. |
| 3523 // Test reuses SyncManagerImpl initialization from SyncManagerTest but overrides |
| 3524 // InternalComponentsFactory to return DirectoryBackingStore that always fails |
| 3525 // to load. |
| 3526 class SyncManagerInitInvalidStorageTest : public SyncManagerTest { |
| 3527 public: |
| 3528 SyncManagerInitInvalidStorageTest() { |
| 3529 } |
| 3530 |
| 3531 virtual InternalComponentsFactory* GetFactory() { |
| 3532 return new TestInternalComponentsFactory(GetSwitches(), STORAGE_INVALID); |
| 3533 } |
| 3534 }; |
| 3535 |
| 3536 // SyncManagerInitInvalidStorageTest::GetFactory will return |
| 3537 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. |
| 3538 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's |
| 3539 // task is to ensure that SyncManagerImpl reported initialization failure in |
| 3540 // OnInitializationComplete callback. |
| 3541 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { |
| 3542 EXPECT_FALSE(initialization_succeeded_); |
| 3543 } |
| 3544 |
| 3517 } // namespace | 3545 } // namespace |
| OLD | NEW |