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 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1233 sync_manager_.TriggerOnIncomingNotificationForTest(model_types); | 1233 sync_manager_.TriggerOnIncomingNotificationForTest(model_types); |
1234 | 1234 |
1235 js_backend->SetParentJsEventRouter(&event_router); | 1235 js_backend->SetParentJsEventRouter(&event_router); |
1236 sync_manager_.TriggerOnIncomingNotificationForTest(model_types); | 1236 sync_manager_.TriggerOnIncomingNotificationForTest(model_types); |
1237 js_backend->RemoveParentJsEventRouter(); | 1237 js_backend->RemoveParentJsEventRouter(); |
1238 | 1238 |
1239 sync_manager_.TriggerOnIncomingNotificationForTest(empty_model_types); | 1239 sync_manager_.TriggerOnIncomingNotificationForTest(empty_model_types); |
1240 sync_manager_.TriggerOnIncomingNotificationForTest(model_types); | 1240 sync_manager_.TriggerOnIncomingNotificationForTest(model_types); |
1241 } | 1241 } |
1242 | 1242 |
| 1243 TEST_F(SyncManagerTest, ReloadNigoriReady) { |
| 1244 EXPECT_TRUE(SetUpEncryption()); |
| 1245 sync_manager_.ReloadNigori(); |
| 1246 syncable::ModelTypeSet encrypted_types = |
| 1247 sync_manager_.GetEncryptedDataTypes(); |
| 1248 EXPECT_EQ(1U, encrypted_types.count(syncable::PASSWORDS)); |
| 1249 } |
| 1250 |
| 1251 // Attempt to reload nigori when nigori not downloaded. |
| 1252 TEST_F(SyncManagerTest, ReloadNigoriNotReady) { |
| 1253 // Don't set up encryption. |
| 1254 sync_manager_.ReloadNigori(); // Should fail. |
| 1255 syncable::ModelTypeSet encrypted_types = |
| 1256 sync_manager_.GetEncryptedDataTypes(); |
| 1257 EXPECT_EQ(1U, encrypted_types.count(syncable::PASSWORDS)); // Hardcoded. |
| 1258 } |
| 1259 |
1243 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) { | 1260 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) { |
1244 EXPECT_TRUE(SetUpEncryption()); | 1261 EXPECT_TRUE(SetUpEncryption()); |
1245 ModelTypeSet encrypted_types; | 1262 ModelTypeSet encrypted_types; |
1246 encrypted_types.insert(syncable::BOOKMARKS); | 1263 encrypted_types.insert(syncable::BOOKMARKS); |
1247 // Even though Passwords isn't marked for encryption, it's enabled, so it | 1264 // Even though Passwords isn't marked for encryption, it's enabled, so it |
1248 // should automatically be added to the response of OnEncryptionComplete. | 1265 // should automatically be added to the response of OnEncryptionComplete. |
1249 ModelTypeSet expected_types = encrypted_types; | 1266 ModelTypeSet expected_types = encrypted_types; |
1250 expected_types.insert(syncable::PASSWORDS); | 1267 expected_types.insert(syncable::PASSWORDS); |
1251 EXPECT_CALL(observer_, OnEncryptionComplete(expected_types)); | 1268 EXPECT_CALL(observer_, OnEncryptionComplete(expected_types)); |
1252 sync_manager_.EncryptDataTypes(encrypted_types); | 1269 sync_manager_.EncryptDataTypes(encrypted_types); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1314 true /* is encrypted */)); | 1331 true /* is encrypted */)); |
1315 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1332 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), |
1316 syncable::SESSIONS, | 1333 syncable::SESSIONS, |
1317 true /* is encrypted */)); | 1334 true /* is encrypted */)); |
1318 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), | 1335 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), |
1319 syncable::THEMES, | 1336 syncable::THEMES, |
1320 false /* not encrypted */)); | 1337 false /* not encrypted */)); |
1321 } | 1338 } |
1322 } | 1339 } |
1323 | 1340 |
| 1341 TEST_F(SyncManagerTest, SetPassphraseWithPassword) { |
| 1342 EXPECT_TRUE(SetUpEncryption()); |
| 1343 { |
| 1344 WriteTransaction trans(sync_manager_.GetUserShare()); |
| 1345 ReadNode root_node(&trans); |
| 1346 root_node.InitByRootLookup(); |
| 1347 |
| 1348 WriteNode password_node(&trans); |
| 1349 EXPECT_TRUE(password_node.InitUniqueByCreation(syncable::PASSWORDS, |
| 1350 root_node, "foo")); |
| 1351 sync_pb::PasswordSpecificsData data; |
| 1352 data.set_password_value("secret"); |
| 1353 password_node.SetPasswordSpecifics(data); |
| 1354 } |
| 1355 EXPECT_CALL(observer_, OnPassphraseAccepted(_)); |
| 1356 EXPECT_CALL(observer_, OnEncryptionComplete(_)); |
| 1357 sync_manager_.SetPassphrase("new_passphrase", true); |
| 1358 { |
| 1359 ReadTransaction trans(sync_manager_.GetUserShare()); |
| 1360 ReadNode root_node(&trans); |
| 1361 root_node.InitByRootLookup(); |
| 1362 |
| 1363 ReadNode password_node(&trans); |
| 1364 EXPECT_TRUE(password_node.InitByClientTagLookup(syncable::PASSWORDS, |
| 1365 "foo")); |
| 1366 const sync_pb::PasswordSpecificsData& data = |
| 1367 password_node.GetPasswordSpecifics(); |
| 1368 EXPECT_EQ("secret", data.password_value()); |
| 1369 } |
| 1370 } |
| 1371 |
| 1372 TEST_F(SyncManagerTest, SetPassphraseWithEmptyPasswordNode) { |
| 1373 EXPECT_TRUE(SetUpEncryption()); |
| 1374 int64 node_id = 0; |
| 1375 std::string tag = "foo"; |
| 1376 { |
| 1377 WriteTransaction trans(sync_manager_.GetUserShare()); |
| 1378 ReadNode root_node(&trans); |
| 1379 root_node.InitByRootLookup(); |
| 1380 |
| 1381 WriteNode password_node(&trans); |
| 1382 EXPECT_TRUE(password_node.InitUniqueByCreation(syncable::PASSWORDS, |
| 1383 root_node, tag)); |
| 1384 node_id = password_node.GetId(); |
| 1385 } |
| 1386 EXPECT_CALL(observer_, OnPassphraseAccepted(_)); |
| 1387 EXPECT_CALL(observer_, OnEncryptionComplete(_)); |
| 1388 sync_manager_.SetPassphrase("new_passphrase", true); |
| 1389 { |
| 1390 ReadTransaction trans(sync_manager_.GetUserShare()); |
| 1391 ReadNode root_node(&trans); |
| 1392 root_node.InitByRootLookup(); |
| 1393 |
| 1394 ReadNode password_node(&trans); |
| 1395 EXPECT_FALSE(password_node.InitByClientTagLookup(syncable::PASSWORDS, |
| 1396 tag)); |
| 1397 } |
| 1398 { |
| 1399 ReadTransaction trans(sync_manager_.GetUserShare()); |
| 1400 ReadNode root_node(&trans); |
| 1401 root_node.InitByRootLookup(); |
| 1402 |
| 1403 ReadNode password_node(&trans); |
| 1404 EXPECT_FALSE(password_node.InitByIdLookup(node_id)); |
| 1405 } |
| 1406 } |
| 1407 |
1324 } // namespace | 1408 } // namespace |
1325 | 1409 |
1326 } // namespace browser_sync | 1410 } // namespace browser_sync |
OLD | NEW |