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

Side by Side Diff: sync/internal_api/sync_manager_impl_unittest.cc

Issue 10832286: sync: Introduce control data types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add ToFullModelTypeSet() function Created 8 years, 3 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 1405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 Cryptographer* cryptographer = trans.GetCryptographer(); 1416 Cryptographer* cryptographer = trans.GetCryptographer();
1417 EXPECT_TRUE(cryptographer->is_ready()); 1417 EXPECT_TRUE(cryptographer->is_ready());
1418 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); 1418 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted()));
1419 } 1419 }
1420 } 1420 }
1421 1421
1422 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) { 1422 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) {
1423 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 1423 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
1424 EXPECT_CALL(encryption_observer_, 1424 EXPECT_CALL(encryption_observer_,
1425 OnEncryptedTypesChanged( 1425 OnEncryptedTypesChanged(
1426 HasModelTypes(ModelTypeSet::All()), true)); 1426 HasModelTypes(UserTypes()), true));
1427 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1427 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1428 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); 1428 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything();
1429 EXPECT_TRUE(EncryptEverythingEnabledForTest()); 1429 EXPECT_TRUE(EncryptEverythingEnabledForTest());
1430 } 1430 }
1431 1431
1432 TEST_F(SyncManagerTest, EncryptDataTypesWithData) { 1432 TEST_F(SyncManagerTest, EncryptDataTypesWithData) {
1433 size_t batch_size = 5; 1433 size_t batch_size = 5;
1434 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 1434 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
1435 1435
1436 // Create some unencrypted unsynced data. 1436 // Create some unencrypted unsynced data.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 SESSIONS, 1470 SESSIONS,
1471 false /* not encrypted */)); 1471 false /* not encrypted */));
1472 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1472 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1473 trans.GetWrappedTrans(), 1473 trans.GetWrappedTrans(),
1474 THEMES, 1474 THEMES,
1475 false /* not encrypted */)); 1475 false /* not encrypted */));
1476 } 1476 }
1477 1477
1478 EXPECT_CALL(encryption_observer_, 1478 EXPECT_CALL(encryption_observer_,
1479 OnEncryptedTypesChanged( 1479 OnEncryptedTypesChanged(
1480 HasModelTypes(ModelTypeSet::All()), true)); 1480 HasModelTypes(UserTypes()), true));
1481 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1481 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1482 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); 1482 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything();
1483 EXPECT_TRUE(EncryptEverythingEnabledForTest()); 1483 EXPECT_TRUE(EncryptEverythingEnabledForTest());
1484 { 1484 {
1485 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1485 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1486 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals( 1486 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals(
1487 ModelTypeSet::All())); 1487 UserTypes()));
1488 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1488 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1489 trans.GetWrappedTrans(), 1489 trans.GetWrappedTrans(),
1490 BOOKMARKS, 1490 BOOKMARKS,
1491 true /* is encrypted */)); 1491 true /* is encrypted */));
1492 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1492 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1493 trans.GetWrappedTrans(), 1493 trans.GetWrappedTrans(),
1494 SESSIONS, 1494 SESSIONS,
1495 true /* is encrypted */)); 1495 true /* is encrypted */));
1496 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1496 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1497 trans.GetWrappedTrans(), 1497 trans.GetWrappedTrans(),
1498 THEMES, 1498 THEMES,
1499 true /* is encrypted */)); 1499 true /* is encrypted */));
1500 } 1500 }
1501 1501
1502 // Trigger's a ReEncryptEverything with new passphrase. 1502 // Trigger's a ReEncryptEverything with new passphrase.
1503 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); 1503 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
1504 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1504 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1505 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1505 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1506 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1506 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1507 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1507 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1508 EXPECT_CALL(encryption_observer_, 1508 EXPECT_CALL(encryption_observer_,
1509 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); 1509 OnPassphraseStateChanged(CUSTOM_PASSPHRASE));
1510 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1510 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1511 "new_passphrase", true); 1511 "new_passphrase", true);
1512 EXPECT_TRUE(EncryptEverythingEnabledForTest()); 1512 EXPECT_TRUE(EncryptEverythingEnabledForTest());
1513 { 1513 {
1514 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1514 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1515 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals(ModelTypeSet::All())); 1515 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals(UserTypes()));
1516 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1516 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1517 trans.GetWrappedTrans(), 1517 trans.GetWrappedTrans(),
1518 BOOKMARKS, 1518 BOOKMARKS,
1519 true /* is encrypted */)); 1519 true /* is encrypted */));
1520 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1520 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1521 trans.GetWrappedTrans(), 1521 trans.GetWrappedTrans(),
1522 SESSIONS, 1522 SESSIONS,
1523 true /* is encrypted */)); 1523 true /* is encrypted */));
1524 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1524 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1525 trans.GetWrappedTrans(), 1525 trans.GetWrappedTrans(),
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
1988 { 1988 {
1989 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1989 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1990 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1990 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1991 trans.GetWrappedTrans(), 1991 trans.GetWrappedTrans(),
1992 BOOKMARKS, 1992 BOOKMARKS,
1993 false /* not encrypted */)); 1993 false /* not encrypted */));
1994 } 1994 }
1995 1995
1996 EXPECT_CALL(encryption_observer_, 1996 EXPECT_CALL(encryption_observer_,
1997 OnEncryptedTypesChanged( 1997 OnEncryptedTypesChanged(
1998 HasModelTypes(ModelTypeSet::All()), true)); 1998 HasModelTypes(UserTypes()), true));
1999 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1999 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2000 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); 2000 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything();
2001 EXPECT_TRUE(EncryptEverythingEnabledForTest()); 2001 EXPECT_TRUE(EncryptEverythingEnabledForTest());
2002 2002
2003 { 2003 {
2004 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2004 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2005 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals(ModelTypeSet::All())); 2005 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals(UserTypes()));
2006 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 2006 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
2007 trans.GetWrappedTrans(), 2007 trans.GetWrappedTrans(),
2008 BOOKMARKS, 2008 BOOKMARKS,
2009 true /* is encrypted */)); 2009 true /* is encrypted */));
2010 2010
2011 ReadNode node(&trans); 2011 ReadNode node(&trans);
2012 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(node_id1)); 2012 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(node_id1));
2013 EXPECT_EQ(BOOKMARKS, node.GetModelType()); 2013 EXPECT_EQ(BOOKMARKS, node.GetModelType());
2014 EXPECT_EQ(title, node.GetTitle()); 2014 EXPECT_EQ(title, node.GetTitle());
2015 EXPECT_EQ(title, node.GetBookmarkSpecifics().title()); 2015 EXPECT_EQ(title, node.GetBookmarkSpecifics().title());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2075 WriteNode node(&trans); 2075 WriteNode node(&trans);
2076 EXPECT_EQ(BaseNode::INIT_OK, 2076 EXPECT_EQ(BaseNode::INIT_OK,
2077 node.InitByClientTagLookup(BOOKMARKS, client_tag)); 2077 node.InitByClientTagLookup(BOOKMARKS, client_tag));
2078 node.SetEntitySpecifics(entity_specifics); 2078 node.SetEntitySpecifics(entity_specifics);
2079 } 2079 }
2080 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); 2080 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag));
2081 2081
2082 // Encrypt the datatatype, should set is_unsynced. 2082 // Encrypt the datatatype, should set is_unsynced.
2083 EXPECT_CALL(encryption_observer_, 2083 EXPECT_CALL(encryption_observer_,
2084 OnEncryptedTypesChanged( 2084 OnEncryptedTypesChanged(
2085 HasModelTypes(ModelTypeSet::All()), true)); 2085 HasModelTypes(UserTypes()), true));
2086 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 2086 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2087 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); 2087 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION));
2088 2088
2089 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 2089 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
2090 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, true)); 2090 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, true));
2091 sync_manager_.GetEncryptionHandler()->Init(); 2091 sync_manager_.GetEncryptionHandler()->Init();
2092 PumpLoop(); 2092 PumpLoop();
2093 { 2093 {
2094 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2094 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2095 ReadNode node(&trans); 2095 ReadNode node(&trans);
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
2398 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, 2398 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag,
2399 BaseNode::GenerateSyncableHash(BOOKMARKS, 2399 BaseNode::GenerateSyncableHash(BOOKMARKS,
2400 client_tag), 2400 client_tag),
2401 entity_specifics); 2401 entity_specifics);
2402 // New node shouldn't start off unsynced. 2402 // New node shouldn't start off unsynced.
2403 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); 2403 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag));
2404 2404
2405 // Encrypt the datatatype, should set is_unsynced. 2405 // Encrypt the datatatype, should set is_unsynced.
2406 EXPECT_CALL(encryption_observer_, 2406 EXPECT_CALL(encryption_observer_,
2407 OnEncryptedTypesChanged( 2407 OnEncryptedTypesChanged(
2408 HasModelTypes(ModelTypeSet::All()), true)); 2408 HasModelTypes(UserTypes()), true));
2409 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 2409 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2410 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); 2410 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION));
2411 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 2411 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
2412 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, true)); 2412 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, true));
2413 sync_manager_.GetEncryptionHandler()->Init(); 2413 sync_manager_.GetEncryptionHandler()->Init();
2414 PumpLoop(); 2414 PumpLoop();
2415 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); 2415 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag));
2416 2416
2417 // Manually change to the same title. Should not set is_unsynced. 2417 // Manually change to the same title. Should not set is_unsynced.
2418 // NON_UNIQUE_NAME should be kEncryptedString. 2418 // NON_UNIQUE_NAME should be kEncryptedString.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
2495 client_tag, 2495 client_tag,
2496 BaseNode::GenerateSyncableHash(PREFERENCES, 2496 BaseNode::GenerateSyncableHash(PREFERENCES,
2497 client_tag), 2497 client_tag),
2498 entity_specifics); 2498 entity_specifics);
2499 // New node shouldn't start off unsynced. 2499 // New node shouldn't start off unsynced.
2500 EXPECT_FALSE(ResetUnsyncedEntry(PREFERENCES, client_tag)); 2500 EXPECT_FALSE(ResetUnsyncedEntry(PREFERENCES, client_tag));
2501 2501
2502 // Encrypt the datatatype, should set is_unsynced. 2502 // Encrypt the datatatype, should set is_unsynced.
2503 EXPECT_CALL(encryption_observer_, 2503 EXPECT_CALL(encryption_observer_,
2504 OnEncryptedTypesChanged( 2504 OnEncryptedTypesChanged(
2505 HasModelTypes(ModelTypeSet::All()), true)); 2505 HasModelTypes(UserTypes()), true));
2506 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 2506 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2507 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); 2507 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION));
2508 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 2508 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
2509 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, true)); 2509 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, true));
2510 sync_manager_.GetEncryptionHandler()->Init(); 2510 sync_manager_.GetEncryptionHandler()->Init();
2511 PumpLoop(); 2511 PumpLoop();
2512 EXPECT_TRUE(ResetUnsyncedEntry(PREFERENCES, client_tag)); 2512 EXPECT_TRUE(ResetUnsyncedEntry(PREFERENCES, client_tag));
2513 2513
2514 // Manually change to the same title. Should not set is_unsynced. 2514 // Manually change to the same title. Should not set is_unsynced.
2515 // NON_UNIQUE_NAME should be kEncryptedString. 2515 // NON_UNIQUE_NAME should be kEncryptedString.
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
2872 2872
2873 // Verify only the non-disabled types remain after cleanup. 2873 // Verify only the non-disabled types remain after cleanup.
2874 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); 2874 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types);
2875 EXPECT_TRUE(new_enabled_types.Equals( 2875 EXPECT_TRUE(new_enabled_types.Equals(
2876 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); 2876 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types)));
2877 EXPECT_TRUE(disabled_types.Equals( 2877 EXPECT_TRUE(disabled_types.Equals(
2878 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); 2878 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All())));
2879 } 2879 }
2880 2880
2881 } // namespace 2881 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698