| 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 // tombstone. | 247 // tombstone. |
| 248 void ReplaceWithTombstone(const ModelType& model_type, | 248 void ReplaceWithTombstone(const ModelType& model_type, |
| 249 const std::string& client_tag); | 249 const std::string& client_tag); |
| 250 | 250 |
| 251 // Save changes to the Directory, destroy it then reload it. | 251 // Save changes to the Directory, destroy it then reload it. |
| 252 bool ReloadDir(); | 252 bool ReloadDir(); |
| 253 | 253 |
| 254 UserShare* user_share(); | 254 UserShare* user_share(); |
| 255 syncable::Directory* dir(); | 255 syncable::Directory* dir(); |
| 256 SyncEncryptionHandler* encryption_handler(); | 256 SyncEncryptionHandler* encryption_handler(); |
| 257 PassphraseType GetPassphraseType(BaseTransaction* trans); |
| 257 | 258 |
| 258 private: | 259 private: |
| 259 base::MessageLoop message_loop_; | 260 base::MessageLoop message_loop_; |
| 260 TestUserShare test_user_share_; | 261 TestUserShare test_user_share_; |
| 261 }; | 262 }; |
| 262 | 263 |
| 263 UserShare* SyncApiTest::user_share() { | 264 UserShare* SyncApiTest::user_share() { |
| 264 return test_user_share_.user_share(); | 265 return test_user_share_.user_share(); |
| 265 } | 266 } |
| 266 | 267 |
| 267 syncable::Directory* SyncApiTest::dir() { | 268 syncable::Directory* SyncApiTest::dir() { |
| 268 return test_user_share_.user_share()->directory.get(); | 269 return test_user_share_.user_share()->directory.get(); |
| 269 } | 270 } |
| 270 | 271 |
| 271 SyncEncryptionHandler* SyncApiTest::encryption_handler() { | 272 SyncEncryptionHandler* SyncApiTest::encryption_handler() { |
| 272 return test_user_share_.encryption_handler(); | 273 return test_user_share_.encryption_handler(); |
| 273 } | 274 } |
| 274 | 275 |
| 276 PassphraseType SyncApiTest::GetPassphraseType(BaseTransaction* trans) { |
| 277 return dir()->GetNigoriHandler()->GetPassphraseType(trans->GetWrappedTrans()); |
| 278 } |
| 279 |
| 275 bool SyncApiTest::ReloadDir() { | 280 bool SyncApiTest::ReloadDir() { |
| 276 return test_user_share_.Reload(); | 281 return test_user_share_.Reload(); |
| 277 } | 282 } |
| 278 | 283 |
| 279 void SyncApiTest::CreateEntryWithAttachmentMetadata( | 284 void SyncApiTest::CreateEntryWithAttachmentMetadata( |
| 280 const ModelType& model_type, | 285 const ModelType& model_type, |
| 281 const std::string& client_tag, | 286 const std::string& client_tag, |
| 282 const sync_pb::AttachmentMetadata& attachment_metadata) { | 287 const sync_pb::AttachmentMetadata& attachment_metadata) { |
| 283 syncer::WriteTransaction trans(FROM_HERE, user_share()); | 288 syncer::WriteTransaction trans(FROM_HERE, user_share()); |
| 284 syncer::ReadNode root_node(&trans); | 289 syncer::ReadNode root_node(&trans); |
| (...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 ModelTypeSet GetEncryptedTypes() { | 1124 ModelTypeSet GetEncryptedTypes() { |
| 1120 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1125 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1121 return GetEncryptedTypesWithTrans(&trans); | 1126 return GetEncryptedTypesWithTrans(&trans); |
| 1122 } | 1127 } |
| 1123 | 1128 |
| 1124 ModelTypeSet GetEncryptedTypesWithTrans(BaseTransaction* trans) { | 1129 ModelTypeSet GetEncryptedTypesWithTrans(BaseTransaction* trans) { |
| 1125 return trans->GetDirectory()->GetNigoriHandler()->GetEncryptedTypes( | 1130 return trans->GetDirectory()->GetNigoriHandler()->GetEncryptedTypes( |
| 1126 trans->GetWrappedTrans()); | 1131 trans->GetWrappedTrans()); |
| 1127 } | 1132 } |
| 1128 | 1133 |
| 1134 PassphraseType GetPassphraseType() { |
| 1135 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1136 return GetPassphraseTypeWithTrans(&trans); |
| 1137 } |
| 1138 |
| 1139 PassphraseType GetPassphraseTypeWithTrans(BaseTransaction* trans) { |
| 1140 return trans->GetDirectory()->GetNigoriHandler()->GetPassphraseType( |
| 1141 trans->GetWrappedTrans()); |
| 1142 } |
| 1143 |
| 1129 void SimulateInvalidatorEnabledForTest(bool is_enabled) { | 1144 void SimulateInvalidatorEnabledForTest(bool is_enabled) { |
| 1130 DCHECK(sync_manager_.thread_checker_.CalledOnValidThread()); | 1145 DCHECK(sync_manager_.thread_checker_.CalledOnValidThread()); |
| 1131 sync_manager_.SetInvalidatorEnabled(is_enabled); | 1146 sync_manager_.SetInvalidatorEnabled(is_enabled); |
| 1132 } | 1147 } |
| 1133 | 1148 |
| 1134 void SetProgressMarkerForType(ModelType type, bool set) { | 1149 void SetProgressMarkerForType(ModelType type, bool set) { |
| 1135 if (set) { | 1150 if (set) { |
| 1136 sync_pb::DataTypeProgressMarker marker; | 1151 sync_pb::DataTypeProgressMarker marker; |
| 1137 marker.set_token("token"); | 1152 marker.set_token("token"); |
| 1138 marker.set_data_type_id(GetSpecificsFieldNumberFromModelType(type)); | 1153 marker.set_data_type_id(GetSpecificsFieldNumberFromModelType(type)); |
| 1139 sync_manager_.directory()->SetDownloadProgress(type, marker); | 1154 sync_manager_.directory()->SetDownloadProgress(type, marker); |
| 1140 } else { | 1155 } else { |
| 1141 sync_pb::DataTypeProgressMarker marker; | 1156 sync_pb::DataTypeProgressMarker marker; |
| 1142 sync_manager_.directory()->SetDownloadProgress(type, marker); | 1157 sync_manager_.directory()->SetDownloadProgress(type, marker); |
| 1143 } | 1158 } |
| 1144 } | 1159 } |
| 1145 | 1160 |
| 1146 InternalComponentsFactory::Switches GetSwitches() const { return switches_; } | 1161 InternalComponentsFactory::Switches GetSwitches() const { return switches_; } |
| 1147 | 1162 |
| 1148 void ExpectPassphraseAcceptance() { | 1163 void ExpectPassphraseAcceptance() { |
| 1149 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1164 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1150 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1165 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1151 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1166 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1152 } | 1167 } |
| 1153 | 1168 |
| 1154 void SetImplicitPassphraseAndCheck(const std::string& passphrase) { | 1169 void SetImplicitPassphraseAndCheck(const std::string& passphrase) { |
| 1155 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, | 1170 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, |
| 1156 false); | 1171 false); |
| 1157 EXPECT_EQ(PassphraseType::IMPLICIT_PASSPHRASE, | 1172 EXPECT_EQ(PassphraseType::IMPLICIT_PASSPHRASE, GetPassphraseType()); |
| 1158 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); | |
| 1159 } | 1173 } |
| 1160 | 1174 |
| 1161 void SetCustomPassphraseAndCheck(const std::string& passphrase) { | 1175 void SetCustomPassphraseAndCheck(const std::string& passphrase) { |
| 1162 EXPECT_CALL(encryption_observer_, | 1176 EXPECT_CALL(encryption_observer_, |
| 1163 OnPassphraseTypeChanged(PassphraseType::CUSTOM_PASSPHRASE, _)); | 1177 OnPassphraseTypeChanged(PassphraseType::CUSTOM_PASSPHRASE, _)); |
| 1164 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, | 1178 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(passphrase, |
| 1165 true); | 1179 true); |
| 1166 EXPECT_EQ(PassphraseType::CUSTOM_PASSPHRASE, | 1180 EXPECT_EQ(PassphraseType::CUSTOM_PASSPHRASE, GetPassphraseType()); |
| 1167 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); | |
| 1168 } | 1181 } |
| 1169 | 1182 |
| 1170 bool HasUnrecoverableError() { | 1183 bool HasUnrecoverableError() { |
| 1171 return mock_unrecoverable_error_handler_.invocation_count() > 0; | 1184 return mock_unrecoverable_error_handler_.invocation_count() > 0; |
| 1172 } | 1185 } |
| 1173 | 1186 |
| 1174 private: | 1187 private: |
| 1175 // Needed by |sync_manager_|. | 1188 // Needed by |sync_manager_|. |
| 1176 base::MessageLoop message_loop_; | 1189 base::MessageLoop message_loop_; |
| 1177 // Needed by |sync_manager_|. | 1190 // Needed by |sync_manager_|. |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1473 sync_pb::NigoriSpecifics nigori; | 1486 sync_pb::NigoriSpecifics nigori; |
| 1474 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); | 1487 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); |
| 1475 cryptographer->SetPendingKeys(nigori.encryption_keybag()); | 1488 cryptographer->SetPendingKeys(nigori.encryption_keybag()); |
| 1476 EXPECT_TRUE(cryptographer->has_pending_keys()); | 1489 EXPECT_TRUE(cryptographer->has_pending_keys()); |
| 1477 node.SetNigoriSpecifics(nigori); | 1490 node.SetNigoriSpecifics(nigori); |
| 1478 } | 1491 } |
| 1479 EXPECT_CALL(encryption_observer_, | 1492 EXPECT_CALL(encryption_observer_, |
| 1480 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 1493 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1481 ExpectPassphraseAcceptance(); | 1494 ExpectPassphraseAcceptance(); |
| 1482 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("passphrase2"); | 1495 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("passphrase2"); |
| 1483 EXPECT_EQ(PassphraseType::IMPLICIT_PASSPHRASE, | 1496 EXPECT_EQ(PassphraseType::IMPLICIT_PASSPHRASE, GetPassphraseType()); |
| 1484 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); | |
| 1485 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); | 1497 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); |
| 1486 { | 1498 { |
| 1487 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1499 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1488 Cryptographer* cryptographer = trans.GetCryptographer(); | 1500 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1489 EXPECT_TRUE(cryptographer->is_ready()); | 1501 EXPECT_TRUE(cryptographer->is_ready()); |
| 1490 // Verify we're encrypting with the new key. | 1502 // Verify we're encrypting with the new key. |
| 1491 sync_pb::EncryptedData encrypted; | 1503 sync_pb::EncryptedData encrypted; |
| 1492 cryptographer->GetKeys(&encrypted); | 1504 cryptographer->GetKeys(&encrypted); |
| 1493 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); | 1505 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); |
| 1494 } | 1506 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1599 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1611 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1600 EXPECT_CALL(encryption_observer_, | 1612 EXPECT_CALL(encryption_observer_, |
| 1601 OnPassphraseTypeChanged(PassphraseType::CUSTOM_PASSPHRASE, _)); | 1613 OnPassphraseTypeChanged(PassphraseType::CUSTOM_PASSPHRASE, _)); |
| 1602 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_, _)); | 1614 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_, _)); |
| 1603 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); | 1615 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); |
| 1604 sync_manager_.GetEncryptionHandler()->Init(); | 1616 sync_manager_.GetEncryptionHandler()->Init(); |
| 1605 EXPECT_CALL(encryption_observer_, | 1617 EXPECT_CALL(encryption_observer_, |
| 1606 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 1618 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1607 ExpectPassphraseAcceptance(); | 1619 ExpectPassphraseAcceptance(); |
| 1608 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("explicit"); | 1620 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("explicit"); |
| 1609 EXPECT_EQ(PassphraseType::CUSTOM_PASSPHRASE, | 1621 EXPECT_EQ(PassphraseType::CUSTOM_PASSPHRASE, GetPassphraseType()); |
| 1610 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); | |
| 1611 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); | 1622 EXPECT_FALSE(IsEncryptEverythingEnabledForTest()); |
| 1612 { | 1623 { |
| 1613 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1624 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1614 Cryptographer* cryptographer = trans.GetCryptographer(); | 1625 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1615 EXPECT_TRUE(cryptographer->is_ready()); | 1626 EXPECT_TRUE(cryptographer->is_ready()); |
| 1616 // Verify we're encrypting with the new key. | 1627 // Verify we're encrypting with the new key. |
| 1617 sync_pb::EncryptedData encrypted; | 1628 sync_pb::EncryptedData encrypted; |
| 1618 cryptographer->GetKeys(&encrypted); | 1629 cryptographer->GetKeys(&encrypted); |
| 1619 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); | 1630 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); |
| 1620 } | 1631 } |
| (...skipping 1702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3323 // SyncManagerInitInvalidStorageTest::GetFactory will return | 3334 // SyncManagerInitInvalidStorageTest::GetFactory will return |
| 3324 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. | 3335 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. |
| 3325 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's | 3336 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's |
| 3326 // task is to ensure that SyncManagerImpl reported initialization failure in | 3337 // task is to ensure that SyncManagerImpl reported initialization failure in |
| 3327 // OnInitializationComplete callback. | 3338 // OnInitializationComplete callback. |
| 3328 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { | 3339 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { |
| 3329 EXPECT_FALSE(initialization_succeeded_); | 3340 EXPECT_FALSE(initialization_succeeded_); |
| 3330 } | 3341 } |
| 3331 | 3342 |
| 3332 } // namespace syncer | 3343 } // namespace syncer |
| OLD | NEW |