Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1785 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 1785 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
| 1786 EXPECT_TRUE(specifics.has_encrypted()); | 1786 EXPECT_TRUE(specifics.has_encrypted()); |
| 1787 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED)); | 1787 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED)); |
| 1788 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 1788 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
| 1789 Cryptographer* cryptographer = trans.GetCryptographer(); | 1789 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1790 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 1790 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( |
| 1791 specifics.encrypted())); | 1791 specifics.encrypted())); |
| 1792 } | 1792 } |
| 1793 } | 1793 } |
| 1794 | 1794 |
| 1795 // Passwords have their own handling for encryption. Verify it does not result | |
| 1796 // in unnecessary writes. | |
| 1797 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.
| |
| 1798 std::string client_tag = "title"; | |
| 1799 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | |
| 1800 sync_pb::EntitySpecifics entity_specifics; | |
| 1801 { | |
| 1802 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | |
| 1803 Cryptographer* cryptographer = trans.GetCryptographer(); | |
| 1804 sync_pb::PasswordSpecificsData data; | |
| 1805 data.set_password_value("secret"); | |
| 1806 cryptographer->Encrypt( | |
| 1807 data, | |
| 1808 entity_specifics.MutableExtension(sync_pb::password)-> | |
| 1809 mutable_encrypted()); | |
| 1810 } | |
| 1811 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag, | |
| 1812 BaseNode::GenerateSyncableHash(syncable::PASSWORDS, | |
| 1813 client_tag), | |
| 1814 entity_specifics); | |
| 1815 // New node shouldn't start off unsynced. | |
| 1816 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); | |
| 1817 | |
| 1818 // Manually change to the same data via SetEntitySpecifics. Should not set | |
| 1819 // is_unsynced. | |
| 1820 { | |
| 1821 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | |
| 1822 WriteNode node(&trans); | |
| 1823 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); | |
| 1824 node.SetEntitySpecifics(entity_specifics); | |
| 1825 } | |
| 1826 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); | |
| 1827 | |
| 1828 // Manually change to the same data via SetPasswordSpecifics. Should not set | |
| 1829 // is_unsynced. | |
| 1830 { | |
| 1831 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | |
| 1832 WriteNode node(&trans); | |
| 1833 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); | |
| 1834 node.SetPasswordSpecifics(node.GetPasswordSpecifics()); | |
| 1835 } | |
| 1836 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); | |
| 1837 | |
| 1838 // Set a new passphrase. Should set is_unsynced. | |
| 1839 testing::Mock::VerifyAndClearExpectations(&observer_); | |
| 1840 EXPECT_CALL(observer_, OnPassphraseAccepted(_)); | |
| 1841 EXPECT_CALL(observer_, OnEncryptionComplete()); | |
| 1842 sync_manager_.SetPassphrase("new_passphrase", true); | |
| 1843 EXPECT_TRUE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); | |
| 1844 | |
| 1845 // Force a re-encrypt everything. Should not set is_unsynced. | |
| 1846 testing::Mock::VerifyAndClearExpectations(&observer_); | |
| 1847 EXPECT_CALL(observer_, OnEncryptionComplete()); | |
| 1848 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, | |
| 1849 base::Unretained(this))); | |
| 1850 scoped_refptr<base::ThreadTestHelper> helper( | |
| 1851 new base::ThreadTestHelper( | |
| 1852 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); | |
| 1853 ASSERT_TRUE(helper->Run()); | |
| 1854 PumpLoop(); | |
| 1855 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); | |
| 1856 | |
| 1857 // Manually change to the same data. Should not set is_unsynced. | |
| 1858 { | |
| 1859 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | |
| 1860 WriteNode node(&trans); | |
| 1861 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); | |
| 1862 node.SetPasswordSpecifics(node.GetPasswordSpecifics()); | |
| 1863 } | |
| 1864 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); | |
| 1865 | |
| 1866 // Manually change to different data. Should set is_unsynced. | |
| 1867 { | |
| 1868 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | |
| 1869 WriteNode node(&trans); | |
| 1870 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); | |
| 1871 Cryptographer* cryptographer = trans.GetCryptographer(); | |
| 1872 sync_pb::PasswordSpecificsData data; | |
| 1873 data.set_password_value("secret2"); | |
| 1874 cryptographer->Encrypt( | |
| 1875 data, | |
| 1876 entity_specifics.MutableExtension(sync_pb::password)-> | |
| 1877 mutable_encrypted()); | |
| 1878 node.SetPasswordSpecifics(data); | |
| 1879 const syncable::Entry* node_entry = node.GetEntry(); | |
| 1880 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED)); | |
| 1881 } | |
| 1882 } | |
| 1883 | |
| 1795 } // namespace browser_sync | 1884 } // namespace browser_sync |
| OLD | NEW |