| 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 "components/sync/core_impl/sync_manager_impl.h" | 9 #include "components/sync/core_impl/sync_manager_impl.h" |
| 10 | 10 |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 // tombstone. | 248 // tombstone. |
| 249 void ReplaceWithTombstone(const ModelType& model_type, | 249 void ReplaceWithTombstone(const ModelType& model_type, |
| 250 const std::string& client_tag); | 250 const std::string& client_tag); |
| 251 | 251 |
| 252 // Save changes to the Directory, destroy it then reload it. | 252 // Save changes to the Directory, destroy it then reload it. |
| 253 bool ReloadDir(); | 253 bool ReloadDir(); |
| 254 | 254 |
| 255 UserShare* user_share(); | 255 UserShare* user_share(); |
| 256 syncable::Directory* dir(); | 256 syncable::Directory* dir(); |
| 257 SyncEncryptionHandler* encryption_handler(); | 257 SyncEncryptionHandler* encryption_handler(); |
| 258 PassphraseType GetPassphraseType(BaseTransaction* trans); |
| 258 | 259 |
| 259 private: | 260 private: |
| 260 base::MessageLoop message_loop_; | 261 base::MessageLoop message_loop_; |
| 261 TestUserShare test_user_share_; | 262 TestUserShare test_user_share_; |
| 262 }; | 263 }; |
| 263 | 264 |
| 264 UserShare* SyncApiTest::user_share() { | 265 UserShare* SyncApiTest::user_share() { |
| 265 return test_user_share_.user_share(); | 266 return test_user_share_.user_share(); |
| 266 } | 267 } |
| 267 | 268 |
| 268 syncable::Directory* SyncApiTest::dir() { | 269 syncable::Directory* SyncApiTest::dir() { |
| 269 return test_user_share_.user_share()->directory.get(); | 270 return test_user_share_.user_share()->directory.get(); |
| 270 } | 271 } |
| 271 | 272 |
| 272 SyncEncryptionHandler* SyncApiTest::encryption_handler() { | 273 SyncEncryptionHandler* SyncApiTest::encryption_handler() { |
| 273 return test_user_share_.encryption_handler(); | 274 return test_user_share_.encryption_handler(); |
| 274 } | 275 } |
| 275 | 276 |
| 277 PassphraseType SyncApiTest::GetPassphraseType(BaseTransaction* trans) { |
| 278 return dir()->GetNigoriHandler()->GetPassphraseType(trans->GetWrappedTrans()); |
| 279 } |
| 280 |
| 276 bool SyncApiTest::ReloadDir() { | 281 bool SyncApiTest::ReloadDir() { |
| 277 return test_user_share_.Reload(); | 282 return test_user_share_.Reload(); |
| 278 } | 283 } |
| 279 | 284 |
| 280 void SyncApiTest::CreateEntryWithAttachmentMetadata( | 285 void SyncApiTest::CreateEntryWithAttachmentMetadata( |
| 281 const ModelType& model_type, | 286 const ModelType& model_type, |
| 282 const std::string& client_tag, | 287 const std::string& client_tag, |
| 283 const sync_pb::AttachmentMetadata& attachment_metadata) { | 288 const sync_pb::AttachmentMetadata& attachment_metadata) { |
| 284 syncer::WriteTransaction trans(FROM_HERE, user_share()); | 289 syncer::WriteTransaction trans(FROM_HERE, user_share()); |
| 285 syncer::ReadNode root_node(&trans); | 290 syncer::ReadNode root_node(&trans); |
| (...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 ModelTypeSet GetEncryptedTypes() { | 1126 ModelTypeSet GetEncryptedTypes() { |
| 1122 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1127 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1123 return GetEncryptedTypesWithTrans(&trans); | 1128 return GetEncryptedTypesWithTrans(&trans); |
| 1124 } | 1129 } |
| 1125 | 1130 |
| 1126 ModelTypeSet GetEncryptedTypesWithTrans(BaseTransaction* trans) { | 1131 ModelTypeSet GetEncryptedTypesWithTrans(BaseTransaction* trans) { |
| 1127 return trans->GetDirectory()->GetNigoriHandler()->GetEncryptedTypes( | 1132 return trans->GetDirectory()->GetNigoriHandler()->GetEncryptedTypes( |
| 1128 trans->GetWrappedTrans()); | 1133 trans->GetWrappedTrans()); |
| 1129 } | 1134 } |
| 1130 | 1135 |
| 1136 PassphraseType GetPassphraseType() { |
| 1137 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1138 return GetPassphraseTypeWithTrans(&trans); |
| 1139 } |
| 1140 |
| 1141 PassphraseType GetPassphraseTypeWithTrans(BaseTransaction* trans) { |
| 1142 return trans->GetDirectory()->GetNigoriHandler()->GetPassphraseType( |
| 1143 trans->GetWrappedTrans()); |
| 1144 } |
| 1145 |
| 1131 void SimulateInvalidatorEnabledForTest(bool is_enabled) { | 1146 void SimulateInvalidatorEnabledForTest(bool is_enabled) { |
| 1132 DCHECK(sync_manager_.thread_checker_.CalledOnValidThread()); | 1147 DCHECK(sync_manager_.thread_checker_.CalledOnValidThread()); |
| 1133 sync_manager_.SetInvalidatorEnabled(is_enabled); | 1148 sync_manager_.SetInvalidatorEnabled(is_enabled); |
| 1134 } | 1149 } |
| 1135 | 1150 |
| 1136 void SetProgressMarkerForType(ModelType type, bool set) { | 1151 void SetProgressMarkerForType(ModelType type, bool set) { |
| 1137 if (set) { | 1152 if (set) { |
| 1138 sync_pb::DataTypeProgressMarker marker; | 1153 sync_pb::DataTypeProgressMarker marker; |
| 1139 marker.set_token("token"); | 1154 marker.set_token("token"); |
| 1140 marker.set_data_type_id(GetSpecificsFieldNumberFromModelType(type)); | 1155 marker.set_data_type_id(GetSpecificsFieldNumberFromModelType(type)); |
| 1141 sync_manager_.directory()->SetDownloadProgress(type, marker); | 1156 sync_manager_.directory()->SetDownloadProgress(type, marker); |
| 1142 } else { | 1157 } else { |
| 1143 sync_pb::DataTypeProgressMarker marker; | 1158 sync_pb::DataTypeProgressMarker marker; |
| 1144 sync_manager_.directory()->SetDownloadProgress(type, marker); | 1159 sync_manager_.directory()->SetDownloadProgress(type, marker); |
| 1145 } | 1160 } |
| 1146 } | 1161 } |
| 1147 | 1162 |
| 1148 InternalComponentsFactory::Switches GetSwitches() const { return switches_; } | 1163 InternalComponentsFactory::Switches GetSwitches() const { return switches_; } |
| 1149 | 1164 |
| 1150 void ExpectPassphraseAcceptance() { | 1165 void ExpectPassphraseAcceptance() { |
| 1151 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1166 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1152 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1167 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1153 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1168 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1154 } | 1169 } |
| 1155 | 1170 |
| 1156 void SetImplicitPassphraseAndCheck(const std::string& passphrase) { | 1171 void SetImplicitPassphraseAndCheck(const std::string& passphrase) { |
| 1157 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, | 1172 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, |
| 1158 false); | 1173 false); |
| 1159 EXPECT_EQ(PassphraseType::IMPLICIT_PASSPHRASE, | 1174 EXPECT_EQ(PassphraseType::IMPLICIT_PASSPHRASE, GetPassphraseType()); |
| 1160 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); | |
| 1161 } | 1175 } |
| 1162 | 1176 |
| 1163 void SetCustomPassphraseAndCheck(const std::string& passphrase) { | 1177 void SetCustomPassphraseAndCheck(const std::string& passphrase) { |
| 1164 EXPECT_CALL(encryption_observer_, | 1178 EXPECT_CALL(encryption_observer_, |
| 1165 OnPassphraseTypeChanged(PassphraseType::CUSTOM_PASSPHRASE, _)); | 1179 OnPassphraseTypeChanged(PassphraseType::CUSTOM_PASSPHRASE, _)); |
| 1166 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, | 1180 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, |
| 1167 true); | 1181 true); |
| 1168 EXPECT_EQ(PassphraseType::CUSTOM_PASSPHRASE, | 1182 EXPECT_EQ(PassphraseType::CUSTOM_PASSPHRASE, GetPassphraseType()); |
| 1169 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); | |
| 1170 } | 1183 } |
| 1171 | 1184 |
| 1172 bool HasUnrecoverableError() { | 1185 bool HasUnrecoverableError() { |
| 1173 return mock_unrecoverable_error_handler_.invocation_count() > 0; | 1186 return mock_unrecoverable_error_handler_.invocation_count() > 0; |
| 1174 } | 1187 } |
| 1175 | 1188 |
| 1176 private: | 1189 private: |
| 1177 // Needed by |sync_manager_|. | 1190 // Needed by |sync_manager_|. |
| 1178 base::MessageLoop message_loop_; | 1191 base::MessageLoop message_loop_; |
| 1179 // Needed by |sync_manager_|. | 1192 // Needed by |sync_manager_|. |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1492 sync_pb::NigoriSpecifics nigori; | 1505 sync_pb::NigoriSpecifics nigori; |
| 1493 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); | 1506 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); |
| 1494 cryptographer->SetPendingKeys(nigori.encryption_keybag()); | 1507 cryptographer->SetPendingKeys(nigori.encryption_keybag()); |
| 1495 EXPECT_TRUE(cryptographer->has_pending_keys()); | 1508 EXPECT_TRUE(cryptographer->has_pending_keys()); |
| 1496 node.SetNigoriSpecifics(nigori); | 1509 node.SetNigoriSpecifics(nigori); |
| 1497 } | 1510 } |
| 1498 EXPECT_CALL(encryption_observer_, | 1511 EXPECT_CALL(encryption_observer_, |
| 1499 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 1512 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1500 ExpectPassphraseAcceptance(); | 1513 ExpectPassphraseAcceptance(); |
| 1501 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("passphrase2"); | 1514 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("passphrase2"); |
| 1502 EXPECT_EQ(PassphraseType::IMPLICIT_PASSPHRASE, | 1515 EXPECT_EQ(PassphraseType::IMPLICIT_PASSPHRASE, GetPassphraseType()); |
| 1503 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); | |
| 1504 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); | 1516 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); |
| 1505 { | 1517 { |
| 1506 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1518 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1507 Cryptographer* cryptographer = trans.GetCryptographer(); | 1519 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1508 EXPECT_TRUE(cryptographer->is_ready()); | 1520 EXPECT_TRUE(cryptographer->is_ready()); |
| 1509 // Verify we're encrypting with the new key. | 1521 // Verify we're encrypting with the new key. |
| 1510 sync_pb::EncryptedData encrypted; | 1522 sync_pb::EncryptedData encrypted; |
| 1511 cryptographer->GetKeys(&encrypted); | 1523 cryptographer->GetKeys(&encrypted); |
| 1512 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); | 1524 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); |
| 1513 } | 1525 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1618 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1630 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1619 EXPECT_CALL(encryption_observer_, | 1631 EXPECT_CALL(encryption_observer_, |
| 1620 OnPassphraseTypeChanged(PassphraseType::CUSTOM_PASSPHRASE, _)); | 1632 OnPassphraseTypeChanged(PassphraseType::CUSTOM_PASSPHRASE, _)); |
| 1621 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_, _)); | 1633 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_, _)); |
| 1622 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); | 1634 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); |
| 1623 sync_manager_.GetEncryptionHandler()->Init(); | 1635 sync_manager_.GetEncryptionHandler()->Init(); |
| 1624 EXPECT_CALL(encryption_observer_, | 1636 EXPECT_CALL(encryption_observer_, |
| 1625 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 1637 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1626 ExpectPassphraseAcceptance(); | 1638 ExpectPassphraseAcceptance(); |
| 1627 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("explicit"); | 1639 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("explicit"); |
| 1628 EXPECT_EQ(PassphraseType::CUSTOM_PASSPHRASE, | 1640 EXPECT_EQ(PassphraseType::CUSTOM_PASSPHRASE, GetPassphraseType()); |
| 1629 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); | |
| 1630 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); | 1641 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); |
| 1631 { | 1642 { |
| 1632 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1643 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1633 Cryptographer* cryptographer = trans.GetCryptographer(); | 1644 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1634 EXPECT_TRUE(cryptographer->is_ready()); | 1645 EXPECT_TRUE(cryptographer->is_ready()); |
| 1635 // Verify we're encrypting with the new key. | 1646 // Verify we're encrypting with the new key. |
| 1636 sync_pb::EncryptedData encrypted; | 1647 sync_pb::EncryptedData encrypted; |
| 1637 cryptographer->GetKeys(&encrypted); | 1648 cryptographer->GetKeys(&encrypted); |
| 1638 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); | 1649 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); |
| 1639 } | 1650 } |
| (...skipping 1702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3342 // SyncManagerInitInvalidStorageTest::GetFactory will return | 3353 // SyncManagerInitInvalidStorageTest::GetFactory will return |
| 3343 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. | 3354 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. |
| 3344 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's | 3355 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's |
| 3345 // task is to ensure that SyncManagerImpl reported initialization failure in | 3356 // task is to ensure that SyncManagerImpl reported initialization failure in |
| 3346 // OnInitializationComplete callback. | 3357 // OnInitializationComplete callback. |
| 3347 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { | 3358 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { |
| 3348 EXPECT_FALSE(initialization_succeeded_); | 3359 EXPECT_FALSE(initialization_succeeded_); |
| 3349 } | 3360 } |
| 3350 | 3361 |
| 3351 } // namespace syncer | 3362 } // namespace syncer |
| OLD | NEW |