| 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 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1245 // Last batch_size nodes are a third type that will not need encryption. | 1245 // Last batch_size nodes are a third type that will not need encryption. |
| 1246 for (; i < 3*batch_size; ++i) { | 1246 for (; i < 3*batch_size; ++i) { |
| 1247 MakeNodeWithParent(sync_manager_.GetUserShare(), syncable::THEMES, | 1247 MakeNodeWithParent(sync_manager_.GetUserShare(), syncable::THEMES, |
| 1248 base::StringPrintf("%"PRIuS"", i), | 1248 base::StringPrintf("%"PRIuS"", i), |
| 1249 GetIdForDataType(syncable::THEMES)); | 1249 GetIdForDataType(syncable::THEMES)); |
| 1250 } | 1250 } |
| 1251 | 1251 |
| 1252 { | 1252 { |
| 1253 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1253 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1254 EXPECT_EQ(Cryptographer::SensitiveTypes(), GetEncryptedTypes(&trans)); | 1254 EXPECT_EQ(Cryptographer::SensitiveTypes(), GetEncryptedTypes(&trans)); |
| 1255 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1255 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1256 trans.GetCryptographer(), | 1256 trans.GetWrappedTrans(), |
| 1257 syncable::BOOKMARKS, | 1257 trans.GetCryptographer(), |
| 1258 false /* not encrypted */)); | 1258 syncable::BOOKMARKS, |
| 1259 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1259 false /* not encrypted */)); |
| 1260 trans.GetCryptographer(), | 1260 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1261 syncable::SESSIONS, | 1261 trans.GetWrappedTrans(), |
| 1262 false /* not encrypted */)); | 1262 trans.GetCryptographer(), |
| 1263 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1263 syncable::SESSIONS, |
| 1264 trans.GetCryptographer(), | 1264 false /* not encrypted */)); |
| 1265 syncable::THEMES, | 1265 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1266 false /* not encrypted */)); | 1266 trans.GetWrappedTrans(), |
| 1267 trans.GetCryptographer(), |
| 1268 syncable::THEMES, |
| 1269 false /* not encrypted */)); |
| 1267 } | 1270 } |
| 1268 | 1271 |
| 1269 EXPECT_CALL(observer_, | 1272 EXPECT_CALL(observer_, |
| 1270 OnEncryptedTypesChanged(GetAllRealModelTypes(), true)); | 1273 OnEncryptedTypesChanged(GetAllRealModelTypes(), true)); |
| 1271 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1274 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 1272 sync_manager_.EnableEncryptEverything(); | 1275 sync_manager_.EnableEncryptEverything(); |
| 1273 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabledForTest()); | 1276 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabledForTest()); |
| 1274 { | 1277 { |
| 1275 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1278 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1276 EXPECT_EQ(GetAllRealModelTypes(), GetEncryptedTypes(&trans)); | 1279 EXPECT_EQ(GetAllRealModelTypes(), GetEncryptedTypes(&trans)); |
| 1277 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1280 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1278 trans.GetCryptographer(), | 1281 trans.GetWrappedTrans(), |
| 1279 syncable::BOOKMARKS, | 1282 trans.GetCryptographer(), |
| 1280 true /* is encrypted */)); | 1283 syncable::BOOKMARKS, |
| 1281 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1284 true /* is encrypted */)); |
| 1282 trans.GetCryptographer(), | 1285 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1283 syncable::SESSIONS, | 1286 trans.GetWrappedTrans(), |
| 1284 true /* is encrypted */)); | 1287 trans.GetCryptographer(), |
| 1285 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1288 syncable::SESSIONS, |
| 1286 trans.GetCryptographer(), | 1289 true /* is encrypted */)); |
| 1287 syncable::THEMES, | 1290 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1288 true /* is encrypted */)); | 1291 trans.GetWrappedTrans(), |
| 1292 trans.GetCryptographer(), |
| 1293 syncable::THEMES, |
| 1294 true /* is encrypted */)); |
| 1289 } | 1295 } |
| 1290 | 1296 |
| 1291 // Trigger's a ReEncryptEverything with new passphrase. | 1297 // Trigger's a ReEncryptEverything with new passphrase. |
| 1292 testing::Mock::VerifyAndClearExpectations(&observer_); | 1298 testing::Mock::VerifyAndClearExpectations(&observer_); |
| 1293 EXPECT_CALL(observer_, OnPassphraseAccepted(_)); | 1299 EXPECT_CALL(observer_, OnPassphraseAccepted(_)); |
| 1294 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1300 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 1295 sync_manager_.SetPassphrase("new_passphrase", true); | 1301 sync_manager_.SetPassphrase("new_passphrase", true); |
| 1296 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabledForTest()); | 1302 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabledForTest()); |
| 1297 { | 1303 { |
| 1298 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1304 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1299 EXPECT_EQ(GetAllRealModelTypes(), GetEncryptedTypes(&trans)); | 1305 EXPECT_EQ(GetAllRealModelTypes(), GetEncryptedTypes(&trans)); |
| 1300 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1306 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1301 trans.GetCryptographer(), | 1307 trans.GetWrappedTrans(), |
| 1302 syncable::BOOKMARKS, | 1308 trans.GetCryptographer(), |
| 1303 true /* is encrypted */)); | 1309 syncable::BOOKMARKS, |
| 1304 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1310 true /* is encrypted */)); |
| 1305 trans.GetCryptographer(), | 1311 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1306 syncable::SESSIONS, | 1312 trans.GetWrappedTrans(), |
| 1307 true /* is encrypted */)); | 1313 trans.GetCryptographer(), |
| 1308 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1314 syncable::SESSIONS, |
| 1309 trans.GetCryptographer(), | 1315 true /* is encrypted */)); |
| 1310 syncable::THEMES, | 1316 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1311 true /* is encrypted */)); | 1317 trans.GetWrappedTrans(), |
| 1318 trans.GetCryptographer(), |
| 1319 syncable::THEMES, |
| 1320 true /* is encrypted */)); |
| 1312 } | 1321 } |
| 1313 // Calling EncryptDataTypes with an empty encrypted types should not trigger | 1322 // Calling EncryptDataTypes with an empty encrypted types should not trigger |
| 1314 // a reencryption and should just notify immediately. | 1323 // a reencryption and should just notify immediately. |
| 1315 // TODO(zea): add logic to ensure nothing was written. | 1324 // TODO(zea): add logic to ensure nothing was written. |
| 1316 testing::Mock::VerifyAndClearExpectations(&observer_); | 1325 testing::Mock::VerifyAndClearExpectations(&observer_); |
| 1317 EXPECT_CALL(observer_, OnPassphraseAccepted(_)).Times(0); | 1326 EXPECT_CALL(observer_, OnPassphraseAccepted(_)).Times(0); |
| 1318 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1327 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 1319 sync_manager_.EnableEncryptEverything(); | 1328 sync_manager_.EnableEncryptEverything(); |
| 1320 } | 1329 } |
| 1321 | 1330 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 EXPECT_EQ(syncable::BOOKMARKS, node2.GetModelType()); | 1447 EXPECT_EQ(syncable::BOOKMARKS, node2.GetModelType()); |
| 1439 // We should de-canonicalize the title in GetTitle(), but the title in the | 1448 // We should de-canonicalize the title in GetTitle(), but the title in the |
| 1440 // specifics should be stored in the server legal form. | 1449 // specifics should be stored in the server legal form. |
| 1441 EXPECT_EQ(raw_title2, node2.GetTitle()); | 1450 EXPECT_EQ(raw_title2, node2.GetTitle()); |
| 1442 EXPECT_EQ(title2, node2.GetBookmarkSpecifics().title()); | 1451 EXPECT_EQ(title2, node2.GetBookmarkSpecifics().title()); |
| 1443 EXPECT_EQ(url2, node2.GetBookmarkSpecifics().url()); | 1452 EXPECT_EQ(url2, node2.GetBookmarkSpecifics().url()); |
| 1444 } | 1453 } |
| 1445 | 1454 |
| 1446 { | 1455 { |
| 1447 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1456 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1448 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1457 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1449 trans.GetCryptographer(), | 1458 trans.GetWrappedTrans(), |
| 1450 syncable::BOOKMARKS, | 1459 trans.GetCryptographer(), |
| 1451 false /* not encrypted */)); | 1460 syncable::BOOKMARKS, |
| 1461 false /* not encrypted */)); |
| 1452 } | 1462 } |
| 1453 | 1463 |
| 1454 EXPECT_CALL(observer_, | 1464 EXPECT_CALL(observer_, |
| 1455 OnEncryptedTypesChanged(GetAllRealModelTypes(), true)); | 1465 OnEncryptedTypesChanged(GetAllRealModelTypes(), true)); |
| 1456 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1466 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 1457 sync_manager_.EnableEncryptEverything(); | 1467 sync_manager_.EnableEncryptEverything(); |
| 1458 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabledForTest()); | 1468 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabledForTest()); |
| 1459 | 1469 |
| 1460 { | 1470 { |
| 1461 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1471 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1462 EXPECT_EQ(GetAllRealModelTypes(), GetEncryptedTypes(&trans)); | 1472 EXPECT_EQ(GetAllRealModelTypes(), GetEncryptedTypes(&trans)); |
| 1463 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1473 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1464 trans.GetCryptographer(), | 1474 trans.GetWrappedTrans(), |
| 1465 syncable::BOOKMARKS, | 1475 trans.GetCryptographer(), |
| 1466 true /* is encrypted */)); | 1476 syncable::BOOKMARKS, |
| 1477 true /* is encrypted */)); |
| 1467 | 1478 |
| 1468 ReadNode node(&trans); | 1479 ReadNode node(&trans); |
| 1469 EXPECT_TRUE(node.InitByIdLookup(node_id1)); | 1480 EXPECT_TRUE(node.InitByIdLookup(node_id1)); |
| 1470 EXPECT_EQ(syncable::BOOKMARKS, node.GetModelType()); | 1481 EXPECT_EQ(syncable::BOOKMARKS, node.GetModelType()); |
| 1471 EXPECT_EQ(title, node.GetTitle()); | 1482 EXPECT_EQ(title, node.GetTitle()); |
| 1472 EXPECT_EQ(title, node.GetBookmarkSpecifics().title()); | 1483 EXPECT_EQ(title, node.GetBookmarkSpecifics().title()); |
| 1473 EXPECT_EQ(url, node.GetBookmarkSpecifics().url()); | 1484 EXPECT_EQ(url, node.GetBookmarkSpecifics().url()); |
| 1474 | 1485 |
| 1475 ReadNode node2(&trans); | 1486 ReadNode node2(&trans); |
| 1476 EXPECT_TRUE(node2.InitByIdLookup(node_id2)); | 1487 EXPECT_TRUE(node2.InitByIdLookup(node_id2)); |
| 1477 EXPECT_EQ(syncable::BOOKMARKS, node2.GetModelType()); | 1488 EXPECT_EQ(syncable::BOOKMARKS, node2.GetModelType()); |
| 1478 // We should de-canonicalize the title in GetTitle(), but the title in the | 1489 // We should de-canonicalize the title in GetTitle(), but the title in the |
| 1479 // specifics should be stored in the server legal form. | 1490 // specifics should be stored in the server legal form. |
| 1480 EXPECT_EQ(raw_title2, node2.GetTitle()); | 1491 EXPECT_EQ(raw_title2, node2.GetTitle()); |
| 1481 EXPECT_EQ(title2, node2.GetBookmarkSpecifics().title()); | 1492 EXPECT_EQ(title2, node2.GetBookmarkSpecifics().title()); |
| 1482 EXPECT_EQ(url2, node2.GetBookmarkSpecifics().url()); | 1493 EXPECT_EQ(url2, node2.GetBookmarkSpecifics().url()); |
| 1483 } | 1494 } |
| 1484 } | 1495 } |
| 1485 | 1496 |
| 1486 } // namespace browser_sync | 1497 } // namespace browser_sync |
| OLD | NEW |