| 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 node.SetIsFolder(true); | 163 node.SetIsFolder(true); |
| 164 return node.GetId(); | 164 return node.GetId(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 // Creates the "synced" root node for a particular datatype. We use the syncable | 167 // Creates the "synced" root node for a particular datatype. We use the syncable |
| 168 // methods here so that the syncer treats these nodes as if they were already | 168 // methods here so that the syncer treats these nodes as if they were already |
| 169 // received from the server. | 169 // received from the server. |
| 170 int64 MakeServerNodeForType(UserShare* share, | 170 int64 MakeServerNodeForType(UserShare* share, |
| 171 ModelType model_type) { | 171 ModelType model_type) { |
| 172 sync_pb::EntitySpecifics specifics; | 172 sync_pb::EntitySpecifics specifics; |
| 173 syncable::AddDefaultExtensionValue(model_type, &specifics); | 173 syncable::AddDefaultFieldValue(model_type, &specifics); |
| 174 syncable::WriteTransaction trans( | 174 syncable::WriteTransaction trans( |
| 175 FROM_HERE, syncable::UNITTEST, share->directory.get()); | 175 FROM_HERE, syncable::UNITTEST, share->directory.get()); |
| 176 // Attempt to lookup by nigori tag. | 176 // Attempt to lookup by nigori tag. |
| 177 std::string type_tag = syncable::ModelTypeToRootTag(model_type); | 177 std::string type_tag = syncable::ModelTypeToRootTag(model_type); |
| 178 syncable::Id node_id = syncable::Id::CreateFromServerId(type_tag); | 178 syncable::Id node_id = syncable::Id::CreateFromServerId(type_tag); |
| 179 syncable::MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, | 179 syncable::MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, |
| 180 node_id); | 180 node_id); |
| 181 EXPECT_TRUE(entry.good()); | 181 EXPECT_TRUE(entry.good()); |
| 182 entry.Put(syncable::BASE_VERSION, 1); | 182 entry.Put(syncable::BASE_VERSION, 1); |
| 183 entry.Put(syncable::SERVER_VERSION, 1); | 183 entry.Put(syncable::SERVER_VERSION, 1); |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 } | 501 } |
| 502 | 502 |
| 503 TEST_F(SyncApiTest, BaseNodeSetSpecifics) { | 503 TEST_F(SyncApiTest, BaseNodeSetSpecifics) { |
| 504 int64 child_id = MakeNode(test_user_share_.user_share(), | 504 int64 child_id = MakeNode(test_user_share_.user_share(), |
| 505 syncable::BOOKMARKS, "testtag"); | 505 syncable::BOOKMARKS, "testtag"); |
| 506 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 506 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 507 WriteNode node(&trans); | 507 WriteNode node(&trans); |
| 508 EXPECT_TRUE(node.InitByIdLookup(child_id)); | 508 EXPECT_TRUE(node.InitByIdLookup(child_id)); |
| 509 | 509 |
| 510 sync_pb::EntitySpecifics entity_specifics; | 510 sync_pb::EntitySpecifics entity_specifics; |
| 511 entity_specifics.MutableExtension(sync_pb::bookmark)-> | 511 entity_specifics.mutable_bookmark()->set_url("http://www.google.com"); |
| 512 set_url("http://www.google.com"); | |
| 513 | 512 |
| 514 EXPECT_NE(entity_specifics.SerializeAsString(), | 513 EXPECT_NE(entity_specifics.SerializeAsString(), |
| 515 node.GetEntitySpecifics().SerializeAsString()); | 514 node.GetEntitySpecifics().SerializeAsString()); |
| 516 node.SetEntitySpecifics(entity_specifics); | 515 node.SetEntitySpecifics(entity_specifics); |
| 517 EXPECT_EQ(entity_specifics.SerializeAsString(), | 516 EXPECT_EQ(entity_specifics.SerializeAsString(), |
| 518 node.GetEntitySpecifics().SerializeAsString()); | 517 node.GetEntitySpecifics().SerializeAsString()); |
| 519 } | 518 } |
| 520 | 519 |
| 521 TEST_F(SyncApiTest, BaseNodeSetSpecificsPreservesUnknownFields) { | 520 TEST_F(SyncApiTest, BaseNodeSetSpecificsPreservesUnknownFields) { |
| 522 int64 child_id = MakeNode(test_user_share_.user_share(), | 521 int64 child_id = MakeNode(test_user_share_.user_share(), |
| 523 syncable::BOOKMARKS, "testtag"); | 522 syncable::BOOKMARKS, "testtag"); |
| 524 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 523 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 525 WriteNode node(&trans); | 524 WriteNode node(&trans); |
| 526 EXPECT_TRUE(node.InitByIdLookup(child_id)); | 525 EXPECT_TRUE(node.InitByIdLookup(child_id)); |
| 527 EXPECT_TRUE(node.GetEntitySpecifics().unknown_fields().empty()); | 526 EXPECT_TRUE(node.GetEntitySpecifics().unknown_fields().empty()); |
| 528 | 527 |
| 529 sync_pb::EntitySpecifics entity_specifics; | 528 sync_pb::EntitySpecifics entity_specifics; |
| 530 entity_specifics.MutableExtension(sync_pb::bookmark)-> | 529 entity_specifics.mutable_bookmark()->set_url("http://www.google.com"); |
| 531 set_url("http://www.google.com"); | |
| 532 entity_specifics.mutable_unknown_fields()->AddFixed32(5, 100); | 530 entity_specifics.mutable_unknown_fields()->AddFixed32(5, 100); |
| 533 node.SetEntitySpecifics(entity_specifics); | 531 node.SetEntitySpecifics(entity_specifics); |
| 534 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); | 532 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); |
| 535 | 533 |
| 536 entity_specifics.mutable_unknown_fields()->Clear(); | 534 entity_specifics.mutable_unknown_fields()->Clear(); |
| 537 node.SetEntitySpecifics(entity_specifics); | 535 node.SetEntitySpecifics(entity_specifics); |
| 538 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); | 536 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); |
| 539 } | 537 } |
| 540 | 538 |
| 541 namespace { | 539 namespace { |
| (...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1805 "testtag"); | 1803 "testtag"); |
| 1806 int64 node_id2 = MakeNode(sync_manager_.GetUserShare(), | 1804 int64 node_id2 = MakeNode(sync_manager_.GetUserShare(), |
| 1807 syncable::BOOKMARKS, | 1805 syncable::BOOKMARKS, |
| 1808 "testtag2"); | 1806 "testtag2"); |
| 1809 { | 1807 { |
| 1810 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1808 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1811 WriteNode node(&trans); | 1809 WriteNode node(&trans); |
| 1812 EXPECT_TRUE(node.InitByIdLookup(node_id1)); | 1810 EXPECT_TRUE(node.InitByIdLookup(node_id1)); |
| 1813 | 1811 |
| 1814 sync_pb::EntitySpecifics entity_specifics; | 1812 sync_pb::EntitySpecifics entity_specifics; |
| 1815 entity_specifics.MutableExtension(sync_pb::bookmark)->set_url(url); | 1813 entity_specifics.mutable_bookmark()->set_url(url); |
| 1816 node.SetEntitySpecifics(entity_specifics); | 1814 node.SetEntitySpecifics(entity_specifics); |
| 1817 | 1815 |
| 1818 // Set the old style title. | 1816 // Set the old style title. |
| 1819 syncable::MutableEntry* node_entry = node.entry_; | 1817 syncable::MutableEntry* node_entry = node.entry_; |
| 1820 node_entry->Put(syncable::NON_UNIQUE_NAME, title); | 1818 node_entry->Put(syncable::NON_UNIQUE_NAME, title); |
| 1821 | 1819 |
| 1822 WriteNode node2(&trans); | 1820 WriteNode node2(&trans); |
| 1823 EXPECT_TRUE(node2.InitByIdLookup(node_id2)); | 1821 EXPECT_TRUE(node2.InitByIdLookup(node_id2)); |
| 1824 | 1822 |
| 1825 sync_pb::EntitySpecifics entity_specifics2; | 1823 sync_pb::EntitySpecifics entity_specifics2; |
| 1826 entity_specifics2.MutableExtension(sync_pb::bookmark)->set_url(url2); | 1824 entity_specifics2.mutable_bookmark()->set_url(url2); |
| 1827 node2.SetEntitySpecifics(entity_specifics2); | 1825 node2.SetEntitySpecifics(entity_specifics2); |
| 1828 | 1826 |
| 1829 // Set the old style title. | 1827 // Set the old style title. |
| 1830 syncable::MutableEntry* node_entry2 = node2.entry_; | 1828 syncable::MutableEntry* node_entry2 = node2.entry_; |
| 1831 node_entry2->Put(syncable::NON_UNIQUE_NAME, title2); | 1829 node_entry2->Put(syncable::NON_UNIQUE_NAME, title2); |
| 1832 } | 1830 } |
| 1833 | 1831 |
| 1834 { | 1832 { |
| 1835 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1833 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1836 ReadNode node(&trans); | 1834 ReadNode node(&trans); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1922 EXPECT_EQ(title, node.GetTitle()); | 1920 EXPECT_EQ(title, node.GetTitle()); |
| 1923 EXPECT_EQ(url, node.GetURL()); | 1921 EXPECT_EQ(url, node.GetURL()); |
| 1924 } | 1922 } |
| 1925 } | 1923 } |
| 1926 | 1924 |
| 1927 // Verifies WriteNode::UpdateEntryWithEncryption does not make unnecessary | 1925 // Verifies WriteNode::UpdateEntryWithEncryption does not make unnecessary |
| 1928 // changes. | 1926 // changes. |
| 1929 TEST_F(SyncManagerTest, UpdateEntryWithEncryption) { | 1927 TEST_F(SyncManagerTest, UpdateEntryWithEncryption) { |
| 1930 std::string client_tag = "title"; | 1928 std::string client_tag = "title"; |
| 1931 sync_pb::EntitySpecifics entity_specifics; | 1929 sync_pb::EntitySpecifics entity_specifics; |
| 1932 entity_specifics.MutableExtension(sync_pb::bookmark)->set_url("url"); | 1930 entity_specifics.mutable_bookmark()->set_url("url"); |
| 1933 entity_specifics.MutableExtension(sync_pb::bookmark)->set_title("title"); | 1931 entity_specifics.mutable_bookmark()->set_title("title"); |
| 1934 MakeServerNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, client_tag, | 1932 MakeServerNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, client_tag, |
| 1935 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, | 1933 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, |
| 1936 client_tag), | 1934 client_tag), |
| 1937 entity_specifics); | 1935 entity_specifics); |
| 1938 // New node shouldn't start off unsynced. | 1936 // New node shouldn't start off unsynced. |
| 1939 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); | 1937 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); |
| 1940 // Manually change to the same data. Should not set is_unsynced. | 1938 // Manually change to the same data. Should not set is_unsynced. |
| 1941 { | 1939 { |
| 1942 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1940 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1943 WriteNode node(&trans); | 1941 WriteNode node(&trans); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2031 EXPECT_FALSE(node_entry->Get(IS_UNSYNCED)); | 2029 EXPECT_FALSE(node_entry->Get(IS_UNSYNCED)); |
| 2032 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2030 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
| 2033 Cryptographer* cryptographer = trans.GetCryptographer(); | 2031 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2034 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 2032 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( |
| 2035 specifics.encrypted())); | 2033 specifics.encrypted())); |
| 2036 } | 2034 } |
| 2037 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); | 2035 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); |
| 2038 | 2036 |
| 2039 // Manually change to different data. Should set is_unsynced. | 2037 // Manually change to different data. Should set is_unsynced. |
| 2040 { | 2038 { |
| 2041 entity_specifics.MutableExtension(sync_pb::bookmark)->set_url("url2"); | 2039 entity_specifics.mutable_bookmark()->set_url("url2"); |
| 2042 entity_specifics.MutableExtension(sync_pb::bookmark)->set_title("title2"); | 2040 entity_specifics.mutable_bookmark()->set_title("title2"); |
| 2043 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2041 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2044 WriteNode node(&trans); | 2042 WriteNode node(&trans); |
| 2045 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); | 2043 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); |
| 2046 node.SetEntitySpecifics(entity_specifics); | 2044 node.SetEntitySpecifics(entity_specifics); |
| 2047 const syncable::Entry* node_entry = node.GetEntry(); | 2045 const syncable::Entry* node_entry = node.GetEntry(); |
| 2048 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2046 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
| 2049 EXPECT_TRUE(specifics.has_encrypted()); | 2047 EXPECT_TRUE(specifics.has_encrypted()); |
| 2050 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED)); | 2048 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED)); |
| 2051 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2049 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
| 2052 Cryptographer* cryptographer = trans.GetCryptographer(); | 2050 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2053 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 2051 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( |
| 2054 specifics.encrypted())); | 2052 specifics.encrypted())); |
| 2055 } | 2053 } |
| 2056 } | 2054 } |
| 2057 | 2055 |
| 2058 // Passwords have their own handling for encryption. Verify it does not result | 2056 // Passwords have their own handling for encryption. Verify it does not result |
| 2059 // in unnecessary writes via SetEntitySpecifics. | 2057 // in unnecessary writes via SetEntitySpecifics. |
| 2060 TEST_F(SyncManagerTest, UpdatePasswordSetEntitySpecificsNoChange) { | 2058 TEST_F(SyncManagerTest, UpdatePasswordSetEntitySpecificsNoChange) { |
| 2061 std::string client_tag = "title"; | 2059 std::string client_tag = "title"; |
| 2062 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2060 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2063 sync_pb::EntitySpecifics entity_specifics; | 2061 sync_pb::EntitySpecifics entity_specifics; |
| 2064 { | 2062 { |
| 2065 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2063 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2066 Cryptographer* cryptographer = trans.GetCryptographer(); | 2064 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2067 sync_pb::PasswordSpecificsData data; | 2065 sync_pb::PasswordSpecificsData data; |
| 2068 data.set_password_value("secret"); | 2066 data.set_password_value("secret"); |
| 2069 cryptographer->Encrypt( | 2067 cryptographer->Encrypt( |
| 2070 data, | 2068 data, |
| 2071 entity_specifics.MutableExtension(sync_pb::password)-> | 2069 entity_specifics.mutable_password()-> |
| 2072 mutable_encrypted()); | 2070 mutable_encrypted()); |
| 2073 } | 2071 } |
| 2074 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag, | 2072 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag, |
| 2075 BaseNode::GenerateSyncableHash(syncable::PASSWORDS, | 2073 BaseNode::GenerateSyncableHash(syncable::PASSWORDS, |
| 2076 client_tag), | 2074 client_tag), |
| 2077 entity_specifics); | 2075 entity_specifics); |
| 2078 // New node shouldn't start off unsynced. | 2076 // New node shouldn't start off unsynced. |
| 2079 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); | 2077 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); |
| 2080 | 2078 |
| 2081 // Manually change to the same data via SetEntitySpecifics. Should not set | 2079 // Manually change to the same data via SetEntitySpecifics. Should not set |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2095 std::string client_tag = "title"; | 2093 std::string client_tag = "title"; |
| 2096 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2094 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2097 sync_pb::EntitySpecifics entity_specifics; | 2095 sync_pb::EntitySpecifics entity_specifics; |
| 2098 { | 2096 { |
| 2099 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2097 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2100 Cryptographer* cryptographer = trans.GetCryptographer(); | 2098 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2101 sync_pb::PasswordSpecificsData data; | 2099 sync_pb::PasswordSpecificsData data; |
| 2102 data.set_password_value("secret"); | 2100 data.set_password_value("secret"); |
| 2103 cryptographer->Encrypt( | 2101 cryptographer->Encrypt( |
| 2104 data, | 2102 data, |
| 2105 entity_specifics.MutableExtension(sync_pb::password)-> | 2103 entity_specifics.mutable_password()-> |
| 2106 mutable_encrypted()); | 2104 mutable_encrypted()); |
| 2107 } | 2105 } |
| 2108 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag, | 2106 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag, |
| 2109 BaseNode::GenerateSyncableHash(syncable::PASSWORDS, | 2107 BaseNode::GenerateSyncableHash(syncable::PASSWORDS, |
| 2110 client_tag), | 2108 client_tag), |
| 2111 entity_specifics); | 2109 entity_specifics); |
| 2112 // New node shouldn't start off unsynced. | 2110 // New node shouldn't start off unsynced. |
| 2113 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); | 2111 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); |
| 2114 | 2112 |
| 2115 // Manually change to the same data via SetPasswordSpecifics. Should not set | 2113 // Manually change to the same data via SetPasswordSpecifics. Should not set |
| 2116 // is_unsynced. | 2114 // is_unsynced. |
| 2117 { | 2115 { |
| 2118 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2116 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2119 WriteNode node(&trans); | 2117 WriteNode node(&trans); |
| 2120 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); | 2118 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); |
| 2121 node.SetPasswordSpecifics(node.GetPasswordSpecifics()); | 2119 node.SetPasswordSpecifics(node.GetPasswordSpecifics()); |
| 2122 } | 2120 } |
| 2123 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); | 2121 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); |
| 2124 | 2122 |
| 2125 // Manually change to different data. Should set is_unsynced. | 2123 // Manually change to different data. Should set is_unsynced. |
| 2126 { | 2124 { |
| 2127 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2125 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2128 WriteNode node(&trans); | 2126 WriteNode node(&trans); |
| 2129 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); | 2127 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); |
| 2130 Cryptographer* cryptographer = trans.GetCryptographer(); | 2128 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2131 sync_pb::PasswordSpecificsData data; | 2129 sync_pb::PasswordSpecificsData data; |
| 2132 data.set_password_value("secret2"); | 2130 data.set_password_value("secret2"); |
| 2133 cryptographer->Encrypt( | 2131 cryptographer->Encrypt( |
| 2134 data, | 2132 data, |
| 2135 entity_specifics.MutableExtension(sync_pb::password)-> | 2133 entity_specifics.mutable_password()->mutable_encrypted()); |
| 2136 mutable_encrypted()); | |
| 2137 node.SetPasswordSpecifics(data); | 2134 node.SetPasswordSpecifics(data); |
| 2138 const syncable::Entry* node_entry = node.GetEntry(); | 2135 const syncable::Entry* node_entry = node.GetEntry(); |
| 2139 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED)); | 2136 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED)); |
| 2140 } | 2137 } |
| 2141 } | 2138 } |
| 2142 | 2139 |
| 2143 // Passwords have their own handling for encryption. Verify setting a new | 2140 // Passwords have their own handling for encryption. Verify setting a new |
| 2144 // passphrase updates the data. | 2141 // passphrase updates the data. |
| 2145 TEST_F(SyncManagerTest, UpdatePasswordNewPassphrase) { | 2142 TEST_F(SyncManagerTest, UpdatePasswordNewPassphrase) { |
| 2146 std::string client_tag = "title"; | 2143 std::string client_tag = "title"; |
| 2147 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2144 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2148 sync_pb::EntitySpecifics entity_specifics; | 2145 sync_pb::EntitySpecifics entity_specifics; |
| 2149 { | 2146 { |
| 2150 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2147 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2151 Cryptographer* cryptographer = trans.GetCryptographer(); | 2148 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2152 sync_pb::PasswordSpecificsData data; | 2149 sync_pb::PasswordSpecificsData data; |
| 2153 data.set_password_value("secret"); | 2150 data.set_password_value("secret"); |
| 2154 cryptographer->Encrypt( | 2151 cryptographer->Encrypt( |
| 2155 data, | 2152 data, |
| 2156 entity_specifics.MutableExtension(sync_pb::password)-> | 2153 entity_specifics.mutable_password()->mutable_encrypted()); |
| 2157 mutable_encrypted()); | |
| 2158 } | 2154 } |
| 2159 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag, | 2155 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag, |
| 2160 BaseNode::GenerateSyncableHash(syncable::PASSWORDS, | 2156 BaseNode::GenerateSyncableHash(syncable::PASSWORDS, |
| 2161 client_tag), | 2157 client_tag), |
| 2162 entity_specifics); | 2158 entity_specifics); |
| 2163 // New node shouldn't start off unsynced. | 2159 // New node shouldn't start off unsynced. |
| 2164 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); | 2160 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); |
| 2165 | 2161 |
| 2166 // Set a new passphrase. Should set is_unsynced. | 2162 // Set a new passphrase. Should set is_unsynced. |
| 2167 testing::Mock::VerifyAndClearExpectations(&observer_); | 2163 testing::Mock::VerifyAndClearExpectations(&observer_); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2178 std::string client_tag = "title"; | 2174 std::string client_tag = "title"; |
| 2179 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2175 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2180 sync_pb::EntitySpecifics entity_specifics; | 2176 sync_pb::EntitySpecifics entity_specifics; |
| 2181 { | 2177 { |
| 2182 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2178 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2183 Cryptographer* cryptographer = trans.GetCryptographer(); | 2179 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2184 sync_pb::PasswordSpecificsData data; | 2180 sync_pb::PasswordSpecificsData data; |
| 2185 data.set_password_value("secret"); | 2181 data.set_password_value("secret"); |
| 2186 cryptographer->Encrypt( | 2182 cryptographer->Encrypt( |
| 2187 data, | 2183 data, |
| 2188 entity_specifics.MutableExtension(sync_pb::password)-> | 2184 entity_specifics.mutable_password()->mutable_encrypted()); |
| 2189 mutable_encrypted()); | |
| 2190 } | 2185 } |
| 2191 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag, | 2186 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag, |
| 2192 BaseNode::GenerateSyncableHash(syncable::PASSWORDS, | 2187 BaseNode::GenerateSyncableHash(syncable::PASSWORDS, |
| 2193 client_tag), | 2188 client_tag), |
| 2194 entity_specifics); | 2189 entity_specifics); |
| 2195 // New node shouldn't start off unsynced. | 2190 // New node shouldn't start off unsynced. |
| 2196 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); | 2191 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); |
| 2197 | 2192 |
| 2198 // Force a re-encrypt everything. Should not set is_unsynced. | 2193 // Force a re-encrypt everything. Should not set is_unsynced. |
| 2199 testing::Mock::VerifyAndClearExpectations(&observer_); | 2194 testing::Mock::VerifyAndClearExpectations(&observer_); |
| 2200 EXPECT_CALL(observer_, OnEncryptionComplete()); | 2195 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 2201 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, | 2196 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, |
| 2202 base::Unretained(this))); | 2197 base::Unretained(this))); |
| 2203 scoped_refptr<base::ThreadTestHelper> helper( | 2198 scoped_refptr<base::ThreadTestHelper> helper( |
| 2204 new base::ThreadTestHelper( | 2199 new base::ThreadTestHelper( |
| 2205 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); | 2200 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); |
| 2206 ASSERT_TRUE(helper->Run()); | 2201 ASSERT_TRUE(helper->Run()); |
| 2207 PumpLoop(); | 2202 PumpLoop(); |
| 2208 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); | 2203 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); |
| 2209 } | 2204 } |
| 2210 | 2205 |
| 2211 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for bookmarks | 2206 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for bookmarks |
| 2212 // when we write the same data, but does set it when we write new data. | 2207 // when we write the same data, but does set it when we write new data. |
| 2213 TEST_F(SyncManagerTest, SetBookmarkTitle) { | 2208 TEST_F(SyncManagerTest, SetBookmarkTitle) { |
| 2214 std::string client_tag = "title"; | 2209 std::string client_tag = "title"; |
| 2215 sync_pb::EntitySpecifics entity_specifics; | 2210 sync_pb::EntitySpecifics entity_specifics; |
| 2216 entity_specifics.MutableExtension(sync_pb::bookmark)->set_url("url"); | 2211 entity_specifics.mutable_bookmark()->set_url("url"); |
| 2217 entity_specifics.MutableExtension(sync_pb::bookmark)->set_title("title"); | 2212 entity_specifics.mutable_bookmark()->set_title("title"); |
| 2218 MakeServerNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, client_tag, | 2213 MakeServerNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, client_tag, |
| 2219 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, | 2214 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, |
| 2220 client_tag), | 2215 client_tag), |
| 2221 entity_specifics); | 2216 entity_specifics); |
| 2222 // New node shouldn't start off unsynced. | 2217 // New node shouldn't start off unsynced. |
| 2223 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); | 2218 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); |
| 2224 | 2219 |
| 2225 // Manually change to the same title. Should not set is_unsynced. | 2220 // Manually change to the same title. Should not set is_unsynced. |
| 2226 { | 2221 { |
| 2227 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2222 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2240 } | 2235 } |
| 2241 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); | 2236 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); |
| 2242 } | 2237 } |
| 2243 | 2238 |
| 2244 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted | 2239 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted |
| 2245 // bookmarks when we write the same data, but does set it when we write new | 2240 // bookmarks when we write the same data, but does set it when we write new |
| 2246 // data. | 2241 // data. |
| 2247 TEST_F(SyncManagerTest, SetBookmarkTitleWithEncryption) { | 2242 TEST_F(SyncManagerTest, SetBookmarkTitleWithEncryption) { |
| 2248 std::string client_tag = "title"; | 2243 std::string client_tag = "title"; |
| 2249 sync_pb::EntitySpecifics entity_specifics; | 2244 sync_pb::EntitySpecifics entity_specifics; |
| 2250 entity_specifics.MutableExtension(sync_pb::bookmark)->set_url("url"); | 2245 entity_specifics.mutable_bookmark()->set_url("url"); |
| 2251 entity_specifics.MutableExtension(sync_pb::bookmark)->set_title("title"); | 2246 entity_specifics.mutable_bookmark()->set_title("title"); |
| 2252 MakeServerNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, client_tag, | 2247 MakeServerNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, client_tag, |
| 2253 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, | 2248 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, |
| 2254 client_tag), | 2249 client_tag), |
| 2255 entity_specifics); | 2250 entity_specifics); |
| 2256 // New node shouldn't start off unsynced. | 2251 // New node shouldn't start off unsynced. |
| 2257 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); | 2252 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); |
| 2258 | 2253 |
| 2259 // Encrypt the datatatype, should set is_unsynced. | 2254 // Encrypt the datatatype, should set is_unsynced. |
| 2260 EXPECT_CALL(observer_, | 2255 EXPECT_CALL(observer_, |
| 2261 OnEncryptedTypesChanged( | 2256 OnEncryptedTypesChanged( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2298 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2293 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
| 2299 } | 2294 } |
| 2300 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); | 2295 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); |
| 2301 } | 2296 } |
| 2302 | 2297 |
| 2303 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for non-bookmarks | 2298 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for non-bookmarks |
| 2304 // when we write the same data, but does set it when we write new data. | 2299 // when we write the same data, but does set it when we write new data. |
| 2305 TEST_F(SyncManagerTest, SetNonBookmarkTitle) { | 2300 TEST_F(SyncManagerTest, SetNonBookmarkTitle) { |
| 2306 std::string client_tag = "title"; | 2301 std::string client_tag = "title"; |
| 2307 sync_pb::EntitySpecifics entity_specifics; | 2302 sync_pb::EntitySpecifics entity_specifics; |
| 2308 entity_specifics.MutableExtension(sync_pb::preference)->set_name("name"); | 2303 entity_specifics.mutable_preference()->set_name("name"); |
| 2309 entity_specifics.MutableExtension(sync_pb::preference)->set_value("value"); | 2304 entity_specifics.mutable_preference()->set_value("value"); |
| 2310 MakeServerNode(sync_manager_.GetUserShare(), | 2305 MakeServerNode(sync_manager_.GetUserShare(), |
| 2311 syncable::PREFERENCES, | 2306 syncable::PREFERENCES, |
| 2312 client_tag, | 2307 client_tag, |
| 2313 BaseNode::GenerateSyncableHash(syncable::PREFERENCES, | 2308 BaseNode::GenerateSyncableHash(syncable::PREFERENCES, |
| 2314 client_tag), | 2309 client_tag), |
| 2315 entity_specifics); | 2310 entity_specifics); |
| 2316 // New node shouldn't start off unsynced. | 2311 // New node shouldn't start off unsynced. |
| 2317 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); | 2312 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); |
| 2318 | 2313 |
| 2319 // Manually change to the same title. Should not set is_unsynced. | 2314 // Manually change to the same title. Should not set is_unsynced. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2334 } | 2329 } |
| 2335 EXPECT_TRUE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); | 2330 EXPECT_TRUE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); |
| 2336 } | 2331 } |
| 2337 | 2332 |
| 2338 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted | 2333 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted |
| 2339 // non-bookmarks when we write the same data or when we write new data | 2334 // non-bookmarks when we write the same data or when we write new data |
| 2340 // data (should remained kEncryptedString). | 2335 // data (should remained kEncryptedString). |
| 2341 TEST_F(SyncManagerTest, SetNonBookmarkTitleWithEncryption) { | 2336 TEST_F(SyncManagerTest, SetNonBookmarkTitleWithEncryption) { |
| 2342 std::string client_tag = "title"; | 2337 std::string client_tag = "title"; |
| 2343 sync_pb::EntitySpecifics entity_specifics; | 2338 sync_pb::EntitySpecifics entity_specifics; |
| 2344 entity_specifics.MutableExtension(sync_pb::preference)->set_name("name"); | 2339 entity_specifics.mutable_preference()->set_name("name"); |
| 2345 entity_specifics.MutableExtension(sync_pb::preference)->set_value("value"); | 2340 entity_specifics.mutable_preference()->set_value("value"); |
| 2346 MakeServerNode(sync_manager_.GetUserShare(), | 2341 MakeServerNode(sync_manager_.GetUserShare(), |
| 2347 syncable::PREFERENCES, | 2342 syncable::PREFERENCES, |
| 2348 client_tag, | 2343 client_tag, |
| 2349 BaseNode::GenerateSyncableHash(syncable::PREFERENCES, | 2344 BaseNode::GenerateSyncableHash(syncable::PREFERENCES, |
| 2350 client_tag), | 2345 client_tag), |
| 2351 entity_specifics); | 2346 entity_specifics); |
| 2352 // New node shouldn't start off unsynced. | 2347 // New node shouldn't start off unsynced. |
| 2353 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); | 2348 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); |
| 2354 | 2349 |
| 2355 // Encrypt the datatatype, should set is_unsynced. | 2350 // Encrypt the datatatype, should set is_unsynced. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2403 std::string client_tag = "tag"; | 2398 std::string client_tag = "tag"; |
| 2404 std::string url = "url"; | 2399 std::string url = "url"; |
| 2405 std::string url2 = "new_url"; | 2400 std::string url2 = "new_url"; |
| 2406 std::string title = "title"; | 2401 std::string title = "title"; |
| 2407 sync_pb::EntitySpecifics entity_specifics; | 2402 sync_pb::EntitySpecifics entity_specifics; |
| 2408 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2403 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2409 { | 2404 { |
| 2410 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2405 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2411 browser_sync::Cryptographer* crypto = trans.GetCryptographer(); | 2406 browser_sync::Cryptographer* crypto = trans.GetCryptographer(); |
| 2412 sync_pb::EntitySpecifics bm_specifics; | 2407 sync_pb::EntitySpecifics bm_specifics; |
| 2413 bm_specifics.MutableExtension(sync_pb::bookmark)->set_title("title"); | 2408 bm_specifics.mutable_bookmark()->set_title("title"); |
| 2414 bm_specifics.MutableExtension(sync_pb::bookmark)->set_url("url"); | 2409 bm_specifics.mutable_bookmark()->set_url("url"); |
| 2415 sync_pb::EncryptedData encrypted; | 2410 sync_pb::EncryptedData encrypted; |
| 2416 crypto->Encrypt(bm_specifics, &encrypted); | 2411 crypto->Encrypt(bm_specifics, &encrypted); |
| 2417 entity_specifics.mutable_encrypted()->CopyFrom(encrypted); | 2412 entity_specifics.mutable_encrypted()->CopyFrom(encrypted); |
| 2418 syncable::AddDefaultExtensionValue(syncable::BOOKMARKS, &entity_specifics); | 2413 syncable::AddDefaultFieldValue(syncable::BOOKMARKS, &entity_specifics); |
| 2419 } | 2414 } |
| 2420 MakeServerNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, client_tag, | 2415 MakeServerNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, client_tag, |
| 2421 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, | 2416 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, |
| 2422 client_tag), | 2417 client_tag), |
| 2423 entity_specifics); | 2418 entity_specifics); |
| 2424 | 2419 |
| 2425 { | 2420 { |
| 2426 // Verify the data. | 2421 // Verify the data. |
| 2427 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2422 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2428 ReadNode node(&trans); | 2423 ReadNode node(&trans); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2447 EXPECT_EQ(title, node.GetTitle()); | 2442 EXPECT_EQ(title, node.GetTitle()); |
| 2448 EXPECT_EQ(GURL(url2), node.GetURL()); | 2443 EXPECT_EQ(GURL(url2), node.GetURL()); |
| 2449 const syncable::Entry* node_entry = node.GetEntry(); | 2444 const syncable::Entry* node_entry = node.GetEntry(); |
| 2450 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2445 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
| 2451 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2446 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
| 2452 EXPECT_TRUE(specifics.has_encrypted()); | 2447 EXPECT_TRUE(specifics.has_encrypted()); |
| 2453 } | 2448 } |
| 2454 } | 2449 } |
| 2455 | 2450 |
| 2456 } // namespace browser_sync | 2451 } // namespace browser_sync |
| OLD | NEW |