| 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 1343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1354 true /* is encrypted */)); | 1354 true /* is encrypted */)); |
| 1355 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1355 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), |
| 1356 trans.GetCryptographer(), | 1356 trans.GetCryptographer(), |
| 1357 syncable::THEMES, | 1357 syncable::THEMES, |
| 1358 false /* not encrypted */)); | 1358 false /* not encrypted */)); |
| 1359 } | 1359 } |
| 1360 | 1360 |
| 1361 // Trigger's a ReEncryptEverything with new passphrase. | 1361 // Trigger's a ReEncryptEverything with new passphrase. |
| 1362 testing::Mock::VerifyAndClearExpectations(&observer_); | 1362 testing::Mock::VerifyAndClearExpectations(&observer_); |
| 1363 EXPECT_CALL(observer_, OnPassphraseAccepted(_)).Times(1); | 1363 EXPECT_CALL(observer_, OnPassphraseAccepted(_)).Times(1); |
| 1364 EXPECT_CALL(observer_, OnEncryptionComplete(_)).Times(1); | 1364 EXPECT_CALL(observer_, OnEncryptionComplete(encrypted_types)).Times(1); |
| 1365 sync_manager_.SetPassphrase("new_passphrase", true); | 1365 sync_manager_.SetPassphrase("new_passphrase", true); |
| 1366 { | 1366 { |
| 1367 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1367 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1368 EXPECT_EQ(encrypted_types, GetEncryptedTypes(&trans)); | 1368 EXPECT_EQ(encrypted_types, GetEncryptedTypes(&trans)); |
| 1369 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1369 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), |
| 1370 trans.GetCryptographer(), | 1370 trans.GetCryptographer(), |
| 1371 syncable::BOOKMARKS, | 1371 syncable::BOOKMARKS, |
| 1372 true /* is encrypted */)); | 1372 true /* is encrypted */)); |
| 1373 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1373 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), |
| 1374 trans.GetCryptographer(), | 1374 trans.GetCryptographer(), |
| 1375 syncable::SESSIONS, | 1375 syncable::SESSIONS, |
| 1376 true /* is encrypted */)); | 1376 true /* is encrypted */)); |
| 1377 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1377 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), |
| 1378 trans.GetCryptographer(), | 1378 trans.GetCryptographer(), |
| 1379 syncable::THEMES, | 1379 syncable::THEMES, |
| 1380 false /* not encrypted */)); | 1380 false /* not encrypted */)); |
| 1381 } | 1381 } |
| 1382 // Calling EncryptDataTypes with the same encrypted types should not trigger | 1382 // Calling EncryptDataTypes with an empty encrypted types should not trigger |
| 1383 // a re-encryption. | 1383 // a reencryption and should just notify immediately. |
| 1384 // TODO(zea): add logic to ensure nothing was written. |
| 1384 testing::Mock::VerifyAndClearExpectations(&observer_); | 1385 testing::Mock::VerifyAndClearExpectations(&observer_); |
| 1385 EXPECT_CALL(observer_, OnPassphraseAccepted(_)).Times(0); | 1386 EXPECT_CALL(observer_, OnPassphraseAccepted(_)).Times(0); |
| 1386 EXPECT_CALL(observer_, OnEncryptionComplete(_)).Times(0); | 1387 EXPECT_CALL(observer_, OnEncryptionComplete(encrypted_types)).Times(1); |
| 1387 sync_manager_.EncryptDataTypes(encrypted_types); | 1388 sync_manager_.EncryptDataTypes(encrypted_types); |
| 1388 } | 1389 } |
| 1389 | 1390 |
| 1390 TEST_F(SyncManagerTest, SetPassphraseWithPassword) { | 1391 TEST_F(SyncManagerTest, SetPassphraseWithPassword) { |
| 1391 EXPECT_TRUE(SetUpEncryption()); | 1392 EXPECT_TRUE(SetUpEncryption()); |
| 1392 { | 1393 { |
| 1393 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1394 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1394 ReadNode root_node(&trans); | 1395 ReadNode root_node(&trans); |
| 1395 root_node.InitByRootLookup(); | 1396 root_node.InitByRootLookup(); |
| 1396 | 1397 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1441 { | 1442 { |
| 1442 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1443 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1443 ReadNode password_node(&trans); | 1444 ReadNode password_node(&trans); |
| 1444 EXPECT_FALSE(password_node.InitByIdLookup(node_id)); | 1445 EXPECT_FALSE(password_node.InitByIdLookup(node_id)); |
| 1445 } | 1446 } |
| 1446 } | 1447 } |
| 1447 | 1448 |
| 1448 } // namespace | 1449 } // namespace |
| 1449 | 1450 |
| 1450 } // namespace browser_sync | 1451 } // namespace browser_sync |
| OLD | NEW |