| 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 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 WRITE_TO_NIGORI | 825 WRITE_TO_NIGORI |
| 826 }; | 826 }; |
| 827 | 827 |
| 828 enum EncryptionStatus { | 828 enum EncryptionStatus { |
| 829 UNINITIALIZED, | 829 UNINITIALIZED, |
| 830 DEFAULT_ENCRYPTION, | 830 DEFAULT_ENCRYPTION, |
| 831 FULL_ENCRYPTION | 831 FULL_ENCRYPTION |
| 832 }; | 832 }; |
| 833 | 833 |
| 834 SyncManagerTest() | 834 SyncManagerTest() |
| 835 : sync_manager_("Test sync manager"), | 835 : sync_manager_("Test sync manager") { |
| 836 mock_unrecoverable_error_handler_(NULL) { | |
| 837 switches_.encryption_method = | 836 switches_.encryption_method = |
| 838 InternalComponentsFactory::ENCRYPTION_KEYSTORE; | 837 InternalComponentsFactory::ENCRYPTION_KEYSTORE; |
| 839 } | 838 } |
| 840 | 839 |
| 841 virtual ~SyncManagerTest() { | 840 virtual ~SyncManagerTest() { |
| 842 } | 841 } |
| 843 | 842 |
| 844 // Test implementation. | 843 // Test implementation. |
| 845 void SetUp() { | 844 void SetUp() { |
| 846 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 845 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 876 args.service_url = GURL("https://example.com/"); | 875 args.service_url = GURL("https://example.com/"); |
| 877 args.post_factory = | 876 args.post_factory = |
| 878 scoped_ptr<HttpPostProviderFactory>(new TestHttpPostProviderFactory()); | 877 scoped_ptr<HttpPostProviderFactory>(new TestHttpPostProviderFactory()); |
| 879 args.workers = workers; | 878 args.workers = workers; |
| 880 args.extensions_activity = extensions_activity_.get(), | 879 args.extensions_activity = extensions_activity_.get(), |
| 881 args.change_delegate = this; | 880 args.change_delegate = this; |
| 882 args.credentials = credentials; | 881 args.credentials = credentials; |
| 883 args.invalidator_client_id = "fake_invalidator_client_id"; | 882 args.invalidator_client_id = "fake_invalidator_client_id"; |
| 884 args.internal_components_factory.reset(GetFactory()); | 883 args.internal_components_factory.reset(GetFactory()); |
| 885 args.encryptor = &encryptor_; | 884 args.encryptor = &encryptor_; |
| 886 mock_unrecoverable_error_handler_ = new MockUnrecoverableErrorHandler(); | 885 args.unrecoverable_error_handler = |
| 887 args.unrecoverable_error_handler.reset(mock_unrecoverable_error_handler_); | 886 MakeWeakHandle(mock_unrecoverable_error_handler_.GetWeakPtr()); |
| 888 args.cancelation_signal = &cancelation_signal_; | 887 args.cancelation_signal = &cancelation_signal_; |
| 889 sync_manager_.Init(&args); | 888 sync_manager_.Init(&args); |
| 890 | 889 |
| 891 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); | 890 sync_manager_.GetEncryptionHandler()->AddObserver(&encryption_observer_); |
| 892 | 891 |
| 893 EXPECT_TRUE(js_backend_.IsInitialized()); | 892 EXPECT_TRUE(js_backend_.IsInitialized()); |
| 894 EXPECT_EQ(InternalComponentsFactory::STORAGE_ON_DISK, | 893 EXPECT_EQ(InternalComponentsFactory::STORAGE_ON_DISK, |
| 895 storage_used_); | 894 storage_used_); |
| 896 | 895 |
| 897 if (initialization_succeeded_) { | 896 if (initialization_succeeded_) { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 EXPECT_CALL(encryption_observer_, | 1071 EXPECT_CALL(encryption_observer_, |
| 1073 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _)); | 1072 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE, _)); |
| 1074 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 1073 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1075 passphrase, | 1074 passphrase, |
| 1076 true); | 1075 true); |
| 1077 EXPECT_EQ(CUSTOM_PASSPHRASE, | 1076 EXPECT_EQ(CUSTOM_PASSPHRASE, |
| 1078 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); | 1077 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); |
| 1079 } | 1078 } |
| 1080 | 1079 |
| 1081 bool HasUnrecoverableError() { | 1080 bool HasUnrecoverableError() { |
| 1082 if (mock_unrecoverable_error_handler_) | 1081 return mock_unrecoverable_error_handler_.invocation_count() > 0; |
| 1083 return mock_unrecoverable_error_handler_->invocation_count() > 0; | |
| 1084 return false; | |
| 1085 } | 1082 } |
| 1086 | 1083 |
| 1087 private: | 1084 private: |
| 1088 // Needed by |sync_manager_|. | 1085 // Needed by |sync_manager_|. |
| 1089 base::MessageLoop message_loop_; | 1086 base::MessageLoop message_loop_; |
| 1090 // Needed by |sync_manager_|. | 1087 // Needed by |sync_manager_|. |
| 1091 base::ScopedTempDir temp_dir_; | 1088 base::ScopedTempDir temp_dir_; |
| 1092 // Sync Id's for the roots of the enabled datatypes. | 1089 // Sync Id's for the roots of the enabled datatypes. |
| 1093 std::map<ModelType, int64> type_roots_; | 1090 std::map<ModelType, int64> type_roots_; |
| 1094 scoped_refptr<ExtensionsActivity> extensions_activity_; | 1091 scoped_refptr<ExtensionsActivity> extensions_activity_; |
| 1095 | 1092 |
| 1096 protected: | 1093 protected: |
| 1097 FakeEncryptor encryptor_; | 1094 FakeEncryptor encryptor_; |
| 1098 SyncManagerImpl sync_manager_; | 1095 SyncManagerImpl sync_manager_; |
| 1099 CancelationSignal cancelation_signal_; | 1096 CancelationSignal cancelation_signal_; |
| 1100 WeakHandle<JsBackend> js_backend_; | 1097 WeakHandle<JsBackend> js_backend_; |
| 1101 bool initialization_succeeded_; | 1098 bool initialization_succeeded_; |
| 1102 StrictMock<SyncManagerObserverMock> manager_observer_; | 1099 StrictMock<SyncManagerObserverMock> manager_observer_; |
| 1103 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; | 1100 StrictMock<SyncEncryptionHandlerObserverMock> encryption_observer_; |
| 1104 InternalComponentsFactory::Switches switches_; | 1101 InternalComponentsFactory::Switches switches_; |
| 1105 InternalComponentsFactory::StorageOption storage_used_; | 1102 InternalComponentsFactory::StorageOption storage_used_; |
| 1106 | 1103 MockUnrecoverableErrorHandler mock_unrecoverable_error_handler_; |
| 1107 // Not owned (ownership is passed to the SyncManager). | |
| 1108 MockUnrecoverableErrorHandler* mock_unrecoverable_error_handler_; | |
| 1109 }; | 1104 }; |
| 1110 | 1105 |
| 1111 TEST_F(SyncManagerTest, GetAllNodesForTypeTest) { | 1106 TEST_F(SyncManagerTest, GetAllNodesForTypeTest) { |
| 1112 ModelSafeRoutingInfo routing_info; | 1107 ModelSafeRoutingInfo routing_info; |
| 1113 GetModelSafeRoutingInfo(&routing_info); | 1108 GetModelSafeRoutingInfo(&routing_info); |
| 1114 sync_manager_.StartSyncingNormally(routing_info, base::Time()); | 1109 sync_manager_.StartSyncingNormally(routing_info, base::Time()); |
| 1115 | 1110 |
| 1116 scoped_ptr<base::ListValue> node_list( | 1111 scoped_ptr<base::ListValue> node_list( |
| 1117 sync_manager_.GetAllNodesForType(syncer::PREFERENCES)); | 1112 sync_manager_.GetAllNodesForType(syncer::PREFERENCES)); |
| 1118 | 1113 |
| (...skipping 2211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3330 // SyncManagerInitInvalidStorageTest::GetFactory will return | 3325 // SyncManagerInitInvalidStorageTest::GetFactory will return |
| 3331 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. | 3326 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. |
| 3332 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's | 3327 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's |
| 3333 // task is to ensure that SyncManagerImpl reported initialization failure in | 3328 // task is to ensure that SyncManagerImpl reported initialization failure in |
| 3334 // OnInitializationComplete callback. | 3329 // OnInitializationComplete callback. |
| 3335 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { | 3330 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { |
| 3336 EXPECT_FALSE(initialization_succeeded_); | 3331 EXPECT_FALSE(initialization_succeeded_); |
| 3337 } | 3332 } |
| 3338 | 3333 |
| 3339 } // namespace syncer | 3334 } // namespace syncer |
| OLD | NEW |