| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 1324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1335 true /* is encrypted */)); | 1335 true /* is encrypted */)); |
| 1336 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1336 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), |
| 1337 trans.GetCryptographer(), | 1337 trans.GetCryptographer(), |
| 1338 syncable::THEMES, | 1338 syncable::THEMES, |
| 1339 false /* not encrypted */)); | 1339 false /* not encrypted */)); |
| 1340 } | 1340 } |
| 1341 | 1341 |
| 1342 // Trigger's a ReEncryptEverything with new passphrase. | 1342 // Trigger's a ReEncryptEverything with new passphrase. |
| 1343 testing::Mock::VerifyAndClearExpectations(&observer_); | 1343 testing::Mock::VerifyAndClearExpectations(&observer_); |
| 1344 EXPECT_CALL(observer_, OnPassphraseAccepted(_)).Times(1); | 1344 EXPECT_CALL(observer_, OnPassphraseAccepted(_)).Times(1); |
| 1345 EXPECT_CALL(observer_, OnEncryptionComplete(_)).Times(1); | 1345 EXPECT_CALL(observer_, OnEncryptionComplete(encrypted_types)).Times(1); |
| 1346 sync_manager_.SetPassphrase("new_passphrase", true); | 1346 sync_manager_.SetPassphrase("new_passphrase", true); |
| 1347 { | 1347 { |
| 1348 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1348 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1349 EXPECT_EQ(encrypted_types, GetEncryptedTypes(&trans)); | 1349 EXPECT_EQ(encrypted_types, GetEncryptedTypes(&trans)); |
| 1350 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1350 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), |
| 1351 trans.GetCryptographer(), | 1351 trans.GetCryptographer(), |
| 1352 syncable::BOOKMARKS, | 1352 syncable::BOOKMARKS, |
| 1353 true /* is encrypted */)); | 1353 true /* is encrypted */)); |
| 1354 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1354 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), |
| 1355 trans.GetCryptographer(), | 1355 trans.GetCryptographer(), |
| 1356 syncable::SESSIONS, | 1356 syncable::SESSIONS, |
| 1357 true /* is encrypted */)); | 1357 true /* is encrypted */)); |
| 1358 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1358 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), |
| 1359 trans.GetCryptographer(), | 1359 trans.GetCryptographer(), |
| 1360 syncable::THEMES, | 1360 syncable::THEMES, |
| 1361 false /* not encrypted */)); | 1361 false /* not encrypted */)); |
| 1362 } | 1362 } |
| 1363 // Calling EncryptDataTypes with the same encrypted types should not trigger | 1363 // Calling EncryptDataTypes with an empty encrypted types should not trigger |
| 1364 // a re-encryption. | 1364 // a reencryption and should just notify immediately. |
| 1365 // TODO(zea): add logic to ensure nothing was written. |
| 1365 testing::Mock::VerifyAndClearExpectations(&observer_); | 1366 testing::Mock::VerifyAndClearExpectations(&observer_); |
| 1366 EXPECT_CALL(observer_, OnPassphraseAccepted(_)).Times(0); | 1367 EXPECT_CALL(observer_, OnPassphraseAccepted(_)).Times(0); |
| 1367 EXPECT_CALL(observer_, OnEncryptionComplete(_)).Times(0); | 1368 EXPECT_CALL(observer_, OnEncryptionComplete(encrypted_types)).Times(1); |
| 1368 sync_manager_.EncryptDataTypes(encrypted_types); | 1369 sync_manager_.EncryptDataTypes(encrypted_types); |
| 1369 } | 1370 } |
| 1370 | 1371 |
| 1371 TEST_F(SyncManagerTest, SetPassphraseWithPassword) { | 1372 TEST_F(SyncManagerTest, SetPassphraseWithPassword) { |
| 1372 EXPECT_TRUE(SetUpEncryption()); | 1373 EXPECT_TRUE(SetUpEncryption()); |
| 1373 { | 1374 { |
| 1374 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1375 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1375 ReadNode root_node(&trans); | 1376 ReadNode root_node(&trans); |
| 1376 root_node.InitByRootLookup(); | 1377 root_node.InitByRootLookup(); |
| 1377 | 1378 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1422 { | 1423 { |
| 1423 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1424 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1424 ReadNode password_node(&trans); | 1425 ReadNode password_node(&trans); |
| 1425 EXPECT_FALSE(password_node.InitByIdLookup(node_id)); | 1426 EXPECT_FALSE(password_node.InitByIdLookup(node_id)); |
| 1426 } | 1427 } |
| 1427 } | 1428 } |
| 1428 | 1429 |
| 1429 } // namespace | 1430 } // namespace |
| 1430 | 1431 |
| 1431 } // namespace browser_sync | 1432 } // namespace browser_sync |
| OLD | NEW |