Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: chrome/browser/sync/internal_api/syncapi_unittest.cc

Issue 8356026: [Sync] Cache encrypted types info in ProfileSyncService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test failures Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 MOCK_METHOD2(OnInitializationComplete, 622 MOCK_METHOD2(OnInitializationComplete,
623 void(const WeakHandle<JsBackend>&, bool)); // NOLINT 623 void(const WeakHandle<JsBackend>&, bool)); // NOLINT
624 MOCK_METHOD1(OnAuthError, void(const GoogleServiceAuthError&)); // NOLINT 624 MOCK_METHOD1(OnAuthError, void(const GoogleServiceAuthError&)); // NOLINT
625 MOCK_METHOD1(OnPassphraseRequired, 625 MOCK_METHOD1(OnPassphraseRequired,
626 void(sync_api::PassphraseRequiredReason)); // NOLINT 626 void(sync_api::PassphraseRequiredReason)); // NOLINT
627 MOCK_METHOD1(OnPassphraseAccepted, void(const std::string&)); // NOLINT 627 MOCK_METHOD1(OnPassphraseAccepted, void(const std::string&)); // NOLINT
628 MOCK_METHOD0(OnStopSyncingPermanently, void()); // NOLINT 628 MOCK_METHOD0(OnStopSyncingPermanently, void()); // NOLINT
629 MOCK_METHOD1(OnUpdatedToken, void(const std::string&)); // NOLINT 629 MOCK_METHOD1(OnUpdatedToken, void(const std::string&)); // NOLINT
630 MOCK_METHOD0(OnClearServerDataFailed, void()); // NOLINT 630 MOCK_METHOD0(OnClearServerDataFailed, void()); // NOLINT
631 MOCK_METHOD0(OnClearServerDataSucceeded, void()); // NOLINT 631 MOCK_METHOD0(OnClearServerDataSucceeded, void()); // NOLINT
632 MOCK_METHOD1(OnEncryptionComplete, void(const ModelTypeSet&)); // NOLINT 632 MOCK_METHOD2(OnEncryptionComplete,
633 void(const ModelTypeSet&, bool)); // NOLINT
633 MOCK_METHOD1(OnActionableError, 634 MOCK_METHOD1(OnActionableError,
634 void(const browser_sync::SyncProtocolError&)); // NOLINT 635 void(const browser_sync::SyncProtocolError&)); // NOLINT
635 }; 636 };
636 637
637 class SyncNotifierMock : public sync_notifier::SyncNotifier { 638 class SyncNotifierMock : public sync_notifier::SyncNotifier {
638 public: 639 public:
639 MOCK_METHOD1(AddObserver, void(sync_notifier::SyncNotifierObserver*)); 640 MOCK_METHOD1(AddObserver, void(sync_notifier::SyncNotifierObserver*));
640 MOCK_METHOD1(RemoveObserver, void(sync_notifier::SyncNotifierObserver*)); 641 MOCK_METHOD1(RemoveObserver, void(sync_notifier::SyncNotifierObserver*));
641 MOCK_METHOD1(SetUniqueId, void(const std::string&)); 642 MOCK_METHOD1(SetUniqueId, void(const std::string&));
642 MOCK_METHOD1(SetState, void(const std::string&)); 643 MOCK_METHOD1(SetState, void(const std::string&));
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 // Don't set up encryption (no nigori node created). 1206 // Don't set up encryption (no nigori node created).
1206 sync_manager_.RefreshEncryption(); // Should fail. 1207 sync_manager_.RefreshEncryption(); // Should fail.
1207 syncable::ModelTypeSet encrypted_types = 1208 syncable::ModelTypeSet encrypted_types =
1208 sync_manager_.GetEncryptedDataTypes(); 1209 sync_manager_.GetEncryptedDataTypes();
1209 EXPECT_EQ(1U, encrypted_types.count(syncable::PASSWORDS)); // Hardcoded. 1210 EXPECT_EQ(1U, encrypted_types.count(syncable::PASSWORDS)); // Hardcoded.
1210 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabled()); 1211 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabled());
1211 } 1212 }
1212 1213
1213 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) { 1214 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) {
1214 EXPECT_TRUE(SetUpEncryption()); 1215 EXPECT_TRUE(SetUpEncryption());
1215 EXPECT_CALL(observer_, OnEncryptionComplete(GetAllRealModelTypes())); 1216 EXPECT_CALL(observer_, OnEncryptionComplete(GetAllRealModelTypes(), true));
1216 sync_manager_.EnableEncryptEverything(); 1217 sync_manager_.EnableEncryptEverything();
1217 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabled()); 1218 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabled());
1218 } 1219 }
1219 1220
1220 TEST_F(SyncManagerTest, EncryptDataTypesWithData) { 1221 TEST_F(SyncManagerTest, EncryptDataTypesWithData) {
1221 size_t batch_size = 5; 1222 size_t batch_size = 5;
1222 EXPECT_TRUE(SetUpEncryption()); 1223 EXPECT_TRUE(SetUpEncryption());
1223 1224
1224 // Create some unencrypted unsynced data. 1225 // Create some unencrypted unsynced data.
1225 int64 folder = MakeFolderWithParent(sync_manager_.GetUserShare(), 1226 int64 folder = MakeFolderWithParent(sync_manager_.GetUserShare(),
(...skipping 29 matching lines...) Expand all
1255 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), 1256 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(),
1256 trans.GetCryptographer(), 1257 trans.GetCryptographer(),
1257 syncable::SESSIONS, 1258 syncable::SESSIONS,
1258 false /* not encrypted */)); 1259 false /* not encrypted */));
1259 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), 1260 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(),
1260 trans.GetCryptographer(), 1261 trans.GetCryptographer(),
1261 syncable::THEMES, 1262 syncable::THEMES,
1262 false /* not encrypted */)); 1263 false /* not encrypted */));
1263 } 1264 }
1264 1265
1265 EXPECT_CALL(observer_, OnEncryptionComplete(GetAllRealModelTypes())); 1266 EXPECT_CALL(observer_, OnEncryptionComplete(GetAllRealModelTypes(), true));
1266 sync_manager_.EnableEncryptEverything(); 1267 sync_manager_.EnableEncryptEverything();
1267 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabled()); 1268 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabled());
1268 { 1269 {
1269 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1270 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1270 EXPECT_EQ(GetAllRealModelTypes(), GetEncryptedTypes(&trans)); 1271 EXPECT_EQ(GetAllRealModelTypes(), GetEncryptedTypes(&trans));
1271 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), 1272 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(),
1272 trans.GetCryptographer(), 1273 trans.GetCryptographer(),
1273 syncable::BOOKMARKS, 1274 syncable::BOOKMARKS,
1274 true /* is encrypted */)); 1275 true /* is encrypted */));
1275 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), 1276 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(),
1276 trans.GetCryptographer(), 1277 trans.GetCryptographer(),
1277 syncable::SESSIONS, 1278 syncable::SESSIONS,
1278 true /* is encrypted */)); 1279 true /* is encrypted */));
1279 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), 1280 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(),
1280 trans.GetCryptographer(), 1281 trans.GetCryptographer(),
1281 syncable::THEMES, 1282 syncable::THEMES,
1282 true /* is encrypted */)); 1283 true /* is encrypted */));
1283 } 1284 }
1284 1285
1285 // Trigger's a ReEncryptEverything with new passphrase. 1286 // Trigger's a ReEncryptEverything with new passphrase.
1286 testing::Mock::VerifyAndClearExpectations(&observer_); 1287 testing::Mock::VerifyAndClearExpectations(&observer_);
1287 EXPECT_CALL(observer_, OnPassphraseAccepted(_)).Times(1); 1288 EXPECT_CALL(observer_, OnPassphraseAccepted(_)).Times(1);
1288 EXPECT_CALL(observer_, OnEncryptionComplete(GetAllRealModelTypes())).Times(1); 1289 EXPECT_CALL(observer_,
1290 OnEncryptionComplete(GetAllRealModelTypes(), true)).Times(1);
1289 sync_manager_.SetPassphrase("new_passphrase", true); 1291 sync_manager_.SetPassphrase("new_passphrase", true);
1290 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabled()); 1292 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabled());
1291 { 1293 {
1292 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1294 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1293 EXPECT_EQ(GetAllRealModelTypes(), GetEncryptedTypes(&trans)); 1295 EXPECT_EQ(GetAllRealModelTypes(), GetEncryptedTypes(&trans));
1294 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), 1296 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(),
1295 trans.GetCryptographer(), 1297 trans.GetCryptographer(),
1296 syncable::BOOKMARKS, 1298 syncable::BOOKMARKS,
1297 true /* is encrypted */)); 1299 true /* is encrypted */));
1298 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), 1300 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(),
1299 trans.GetCryptographer(), 1301 trans.GetCryptographer(),
1300 syncable::SESSIONS, 1302 syncable::SESSIONS,
1301 true /* is encrypted */)); 1303 true /* is encrypted */));
1302 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), 1304 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(),
1303 trans.GetCryptographer(), 1305 trans.GetCryptographer(),
1304 syncable::THEMES, 1306 syncable::THEMES,
1305 true /* is encrypted */)); 1307 true /* is encrypted */));
1306 } 1308 }
1307 // Calling EncryptDataTypes with an empty encrypted types should not trigger 1309 // Calling EncryptDataTypes with an empty encrypted types should not trigger
1308 // a reencryption and should just notify immediately. 1310 // a reencryption and should just notify immediately.
1309 // TODO(zea): add logic to ensure nothing was written. 1311 // TODO(zea): add logic to ensure nothing was written.
1310 testing::Mock::VerifyAndClearExpectations(&observer_); 1312 testing::Mock::VerifyAndClearExpectations(&observer_);
1311 EXPECT_CALL(observer_, OnPassphraseAccepted(_)).Times(0); 1313 EXPECT_CALL(observer_, OnPassphraseAccepted(_)).Times(0);
1312 EXPECT_CALL(observer_, OnEncryptionComplete(GetAllRealModelTypes())).Times(1); 1314 EXPECT_CALL(observer_,
1315 OnEncryptionComplete(GetAllRealModelTypes(), true)).Times(1);
1313 sync_manager_.EnableEncryptEverything(); 1316 sync_manager_.EnableEncryptEverything();
1314 } 1317 }
1315 1318
1316 TEST_F(SyncManagerTest, SetPassphraseWithPassword) { 1319 TEST_F(SyncManagerTest, SetPassphraseWithPassword) {
1317 EXPECT_TRUE(SetUpEncryption()); 1320 EXPECT_TRUE(SetUpEncryption());
1318 { 1321 {
1319 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1322 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1320 ReadNode root_node(&trans); 1323 ReadNode root_node(&trans);
1321 root_node.InitByRootLookup(); 1324 root_node.InitByRootLookup();
1322 1325
1323 WriteNode password_node(&trans); 1326 WriteNode password_node(&trans);
1324 EXPECT_TRUE(password_node.InitUniqueByCreation(syncable::PASSWORDS, 1327 EXPECT_TRUE(password_node.InitUniqueByCreation(syncable::PASSWORDS,
1325 root_node, "foo")); 1328 root_node, "foo"));
1326 sync_pb::PasswordSpecificsData data; 1329 sync_pb::PasswordSpecificsData data;
1327 data.set_password_value("secret"); 1330 data.set_password_value("secret");
1328 password_node.SetPasswordSpecifics(data); 1331 password_node.SetPasswordSpecifics(data);
1329 } 1332 }
1330 EXPECT_CALL(observer_, OnPassphraseAccepted(_)); 1333 EXPECT_CALL(observer_, OnPassphraseAccepted(_));
1331 EXPECT_CALL(observer_, OnEncryptionComplete(_)); 1334 EXPECT_CALL(observer_, OnEncryptionComplete(_, false));
1332 sync_manager_.SetPassphrase("new_passphrase", true); 1335 sync_manager_.SetPassphrase("new_passphrase", true);
1333 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabled()); 1336 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabled());
1334 { 1337 {
1335 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1338 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1336 ReadNode password_node(&trans); 1339 ReadNode password_node(&trans);
1337 EXPECT_TRUE(password_node.InitByClientTagLookup(syncable::PASSWORDS, 1340 EXPECT_TRUE(password_node.InitByClientTagLookup(syncable::PASSWORDS,
1338 "foo")); 1341 "foo"));
1339 const sync_pb::PasswordSpecificsData& data = 1342 const sync_pb::PasswordSpecificsData& data =
1340 password_node.GetPasswordSpecifics(); 1343 password_node.GetPasswordSpecifics();
1341 EXPECT_EQ("secret", data.password_value()); 1344 EXPECT_EQ("secret", data.password_value());
1342 } 1345 }
1343 } 1346 }
1344 1347
1345 TEST_F(SyncManagerTest, SetPassphraseWithEmptyPasswordNode) { 1348 TEST_F(SyncManagerTest, SetPassphraseWithEmptyPasswordNode) {
1346 EXPECT_TRUE(SetUpEncryption()); 1349 EXPECT_TRUE(SetUpEncryption());
1347 int64 node_id = 0; 1350 int64 node_id = 0;
1348 std::string tag = "foo"; 1351 std::string tag = "foo";
1349 { 1352 {
1350 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1353 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1351 ReadNode root_node(&trans); 1354 ReadNode root_node(&trans);
1352 root_node.InitByRootLookup(); 1355 root_node.InitByRootLookup();
1353 1356
1354 WriteNode password_node(&trans); 1357 WriteNode password_node(&trans);
1355 EXPECT_TRUE(password_node.InitUniqueByCreation(syncable::PASSWORDS, 1358 EXPECT_TRUE(password_node.InitUniqueByCreation(syncable::PASSWORDS,
1356 root_node, tag)); 1359 root_node, tag));
1357 node_id = password_node.GetId(); 1360 node_id = password_node.GetId();
1358 } 1361 }
1359 EXPECT_CALL(observer_, OnPassphraseAccepted(_)); 1362 EXPECT_CALL(observer_, OnPassphraseAccepted(_));
1360 EXPECT_CALL(observer_, OnEncryptionComplete(_)); 1363 EXPECT_CALL(observer_, OnEncryptionComplete(_, false));
1361 sync_manager_.SetPassphrase("new_passphrase", true); 1364 sync_manager_.SetPassphrase("new_passphrase", true);
1362 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabled()); 1365 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabled());
1363 { 1366 {
1364 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1367 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1365 ReadNode password_node(&trans); 1368 ReadNode password_node(&trans);
1366 EXPECT_FALSE(password_node.InitByClientTagLookup(syncable::PASSWORDS, 1369 EXPECT_FALSE(password_node.InitByClientTagLookup(syncable::PASSWORDS,
1367 tag)); 1370 tag));
1368 } 1371 }
1369 { 1372 {
1370 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1373 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 } 1441 }
1439 1442
1440 { 1443 {
1441 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1444 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1442 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), 1445 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(),
1443 trans.GetCryptographer(), 1446 trans.GetCryptographer(),
1444 syncable::BOOKMARKS, 1447 syncable::BOOKMARKS,
1445 false /* not encrypted */)); 1448 false /* not encrypted */));
1446 } 1449 }
1447 1450
1448 EXPECT_CALL(observer_, OnEncryptionComplete(GetAllRealModelTypes())); 1451 EXPECT_CALL(observer_, OnEncryptionComplete(GetAllRealModelTypes(), true));
1449 sync_manager_.EnableEncryptEverything(); 1452 sync_manager_.EnableEncryptEverything();
1450 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabled()); 1453 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabled());
1451 1454
1452 { 1455 {
1453 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1456 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1454 EXPECT_EQ(GetAllRealModelTypes(), GetEncryptedTypes(&trans)); 1457 EXPECT_EQ(GetAllRealModelTypes(), GetEncryptedTypes(&trans));
1455 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(), 1458 EXPECT_TRUE(syncable::VerifyDataTypeEncryption(trans.GetWrappedTrans(),
1456 trans.GetCryptographer(), 1459 trans.GetCryptographer(),
1457 syncable::BOOKMARKS, 1460 syncable::BOOKMARKS,
1458 true /* is encrypted */)); 1461 true /* is encrypted */));
(...skipping 10 matching lines...) Expand all
1469 EXPECT_EQ(syncable::BOOKMARKS, node2.GetModelType()); 1472 EXPECT_EQ(syncable::BOOKMARKS, node2.GetModelType());
1470 // We should de-canonicalize the title in GetTitle(), but the title in the 1473 // We should de-canonicalize the title in GetTitle(), but the title in the
1471 // specifics should be stored in the server legal form. 1474 // specifics should be stored in the server legal form.
1472 EXPECT_EQ(raw_title2, node2.GetTitle()); 1475 EXPECT_EQ(raw_title2, node2.GetTitle());
1473 EXPECT_EQ(title2, node2.GetBookmarkSpecifics().title()); 1476 EXPECT_EQ(title2, node2.GetBookmarkSpecifics().title());
1474 EXPECT_EQ(url2, node2.GetBookmarkSpecifics().url()); 1477 EXPECT_EQ(url2, node2.GetBookmarkSpecifics().url());
1475 } 1478 }
1476 } 1479 }
1477 1480
1478 } // namespace browser_sync 1481 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698