Index: chrome/browser/sync/internal_api/syncapi_unittest.cc |
diff --git a/chrome/browser/sync/internal_api/syncapi_unittest.cc b/chrome/browser/sync/internal_api/syncapi_unittest.cc |
index 0fb6e4a97f39b97fe0c9c3e1fdae59e068810530..041498178dd763efa5d5552d1540cc71ab4b88f0 100644 |
--- a/chrome/browser/sync/internal_api/syncapi_unittest.cc |
+++ b/chrome/browser/sync/internal_api/syncapi_unittest.cc |
@@ -1792,4 +1792,93 @@ TEST_F(SyncManagerTest, UpdateEntryWithEncryption) { |
} |
} |
+// Passwords have their own handling for encryption. Verify it does not result |
+// in unnecessary writes. |
+TEST_F(SyncManagerTest, UpdatePasswordsData) { |
rlarocque
2012/02/02 18:55:31
Could you split this into several different tests?
Nicolas Zea
2012/02/02 19:54:36
Done.
|
+ std::string client_tag = "title"; |
+ EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
+ sync_pb::EntitySpecifics entity_specifics; |
+ { |
+ ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
+ Cryptographer* cryptographer = trans.GetCryptographer(); |
+ sync_pb::PasswordSpecificsData data; |
+ data.set_password_value("secret"); |
+ cryptographer->Encrypt( |
+ data, |
+ entity_specifics.MutableExtension(sync_pb::password)-> |
+ mutable_encrypted()); |
+ } |
+ MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag, |
+ BaseNode::GenerateSyncableHash(syncable::PASSWORDS, |
+ client_tag), |
+ entity_specifics); |
+ // New node shouldn't start off unsynced. |
+ EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); |
+ |
+ // Manually change to the same data via SetEntitySpecifics. Should not set |
+ // is_unsynced. |
+ { |
+ WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
+ WriteNode node(&trans); |
+ EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); |
+ node.SetEntitySpecifics(entity_specifics); |
+ } |
+ EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); |
+ |
+ // Manually change to the same data via SetPasswordSpecifics. Should not set |
+ // is_unsynced. |
+ { |
+ WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
+ WriteNode node(&trans); |
+ EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); |
+ node.SetPasswordSpecifics(node.GetPasswordSpecifics()); |
+ } |
+ EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); |
+ |
+ // Set a new passphrase. Should set is_unsynced. |
+ testing::Mock::VerifyAndClearExpectations(&observer_); |
+ EXPECT_CALL(observer_, OnPassphraseAccepted(_)); |
+ EXPECT_CALL(observer_, OnEncryptionComplete()); |
+ sync_manager_.SetPassphrase("new_passphrase", true); |
+ EXPECT_TRUE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); |
+ |
+ // Force a re-encrypt everything. Should not set is_unsynced. |
+ testing::Mock::VerifyAndClearExpectations(&observer_); |
+ EXPECT_CALL(observer_, OnEncryptionComplete()); |
+ sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, |
+ base::Unretained(this))); |
+ scoped_refptr<base::ThreadTestHelper> helper( |
+ new base::ThreadTestHelper( |
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); |
+ ASSERT_TRUE(helper->Run()); |
+ PumpLoop(); |
+ EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); |
+ |
+ // Manually change to the same data. Should not set is_unsynced. |
+ { |
+ WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
+ WriteNode node(&trans); |
+ EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); |
+ node.SetPasswordSpecifics(node.GetPasswordSpecifics()); |
+ } |
+ EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); |
+ |
+ // Manually change to different data. Should set is_unsynced. |
+ { |
+ WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
+ WriteNode node(&trans); |
+ EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); |
+ Cryptographer* cryptographer = trans.GetCryptographer(); |
+ sync_pb::PasswordSpecificsData data; |
+ data.set_password_value("secret2"); |
+ cryptographer->Encrypt( |
+ data, |
+ entity_specifics.MutableExtension(sync_pb::password)-> |
+ mutable_encrypted()); |
+ node.SetPasswordSpecifics(data); |
+ const syncable::Entry* node_entry = node.GetEntry(); |
+ EXPECT_TRUE(node_entry->Get(IS_UNSYNCED)); |
+ } |
+} |
+ |
} // namespace browser_sync |