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 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 } | 502 } |
503 | 503 |
504 TEST_F(SyncApiTest, BaseNodeSetSpecifics) { | 504 TEST_F(SyncApiTest, BaseNodeSetSpecifics) { |
505 int64 child_id = MakeNode(test_user_share_.user_share(), | 505 int64 child_id = MakeNode(test_user_share_.user_share(), |
506 syncable::BOOKMARKS, "testtag"); | 506 syncable::BOOKMARKS, "testtag"); |
507 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 507 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
508 WriteNode node(&trans); | 508 WriteNode node(&trans); |
509 EXPECT_TRUE(node.InitByIdLookup(child_id)); | 509 EXPECT_TRUE(node.InitByIdLookup(child_id)); |
510 | 510 |
511 sync_pb::EntitySpecifics entity_specifics; | 511 sync_pb::EntitySpecifics entity_specifics; |
512 entity_specifics.MutableExtension(sync_pb::bookmark)-> | 512 entity_specifics.mutable_bookmark()->set_url("http://www.google.com"); |
513 set_url("http://www.google.com"); | |
514 | 513 |
515 EXPECT_NE(entity_specifics.SerializeAsString(), | 514 EXPECT_NE(entity_specifics.SerializeAsString(), |
516 node.GetEntitySpecifics().SerializeAsString()); | 515 node.GetEntitySpecifics().SerializeAsString()); |
517 node.SetEntitySpecifics(entity_specifics); | 516 node.SetEntitySpecifics(entity_specifics); |
518 EXPECT_EQ(entity_specifics.SerializeAsString(), | 517 EXPECT_EQ(entity_specifics.SerializeAsString(), |
519 node.GetEntitySpecifics().SerializeAsString()); | 518 node.GetEntitySpecifics().SerializeAsString()); |
520 } | 519 } |
521 | 520 |
522 TEST_F(SyncApiTest, BaseNodeSetSpecificsPreservesUnknownFields) { | 521 TEST_F(SyncApiTest, BaseNodeSetSpecificsPreservesUnknownFields) { |
523 int64 child_id = MakeNode(test_user_share_.user_share(), | 522 int64 child_id = MakeNode(test_user_share_.user_share(), |
524 syncable::BOOKMARKS, "testtag"); | 523 syncable::BOOKMARKS, "testtag"); |
525 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 524 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
526 WriteNode node(&trans); | 525 WriteNode node(&trans); |
527 EXPECT_TRUE(node.InitByIdLookup(child_id)); | 526 EXPECT_TRUE(node.InitByIdLookup(child_id)); |
528 EXPECT_TRUE(node.GetEntitySpecifics().unknown_fields().empty()); | 527 EXPECT_TRUE(node.GetEntitySpecifics().unknown_fields().empty()); |
529 | 528 |
530 sync_pb::EntitySpecifics entity_specifics; | 529 sync_pb::EntitySpecifics entity_specifics; |
531 entity_specifics.MutableExtension(sync_pb::bookmark)-> | 530 entity_specifics.mutable_bookmark()->set_url("http://www.google.com"); |
532 set_url("http://www.google.com"); | |
533 entity_specifics.mutable_unknown_fields()->AddFixed32(5, 100); | 531 entity_specifics.mutable_unknown_fields()->AddFixed32(5, 100); |
534 node.SetEntitySpecifics(entity_specifics); | 532 node.SetEntitySpecifics(entity_specifics); |
535 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); | 533 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); |
536 | 534 |
537 entity_specifics.mutable_unknown_fields()->Clear(); | 535 entity_specifics.mutable_unknown_fields()->Clear(); |
538 node.SetEntitySpecifics(entity_specifics); | 536 node.SetEntitySpecifics(entity_specifics); |
539 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); | 537 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); |
540 } | 538 } |
541 | 539 |
542 namespace { | 540 namespace { |
(...skipping 1272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1815 "testtag"); | 1813 "testtag"); |
1816 int64 node_id2 = MakeNode(sync_manager_.GetUserShare(), | 1814 int64 node_id2 = MakeNode(sync_manager_.GetUserShare(), |
1817 syncable::BOOKMARKS, | 1815 syncable::BOOKMARKS, |
1818 "testtag2"); | 1816 "testtag2"); |
1819 { | 1817 { |
1820 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1818 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
1821 WriteNode node(&trans); | 1819 WriteNode node(&trans); |
1822 EXPECT_TRUE(node.InitByIdLookup(node_id1)); | 1820 EXPECT_TRUE(node.InitByIdLookup(node_id1)); |
1823 | 1821 |
1824 sync_pb::EntitySpecifics entity_specifics; | 1822 sync_pb::EntitySpecifics entity_specifics; |
1825 entity_specifics.MutableExtension(sync_pb::bookmark)->set_url(url); | 1823 entity_specifics.mutable_bookmark()->set_url(url); |
1826 node.SetEntitySpecifics(entity_specifics); | 1824 node.SetEntitySpecifics(entity_specifics); |
1827 | 1825 |
1828 // Set the old style title. | 1826 // Set the old style title. |
1829 syncable::MutableEntry* node_entry = node.entry_; | 1827 syncable::MutableEntry* node_entry = node.entry_; |
1830 node_entry->Put(syncable::NON_UNIQUE_NAME, title); | 1828 node_entry->Put(syncable::NON_UNIQUE_NAME, title); |
1831 | 1829 |
1832 WriteNode node2(&trans); | 1830 WriteNode node2(&trans); |
1833 EXPECT_TRUE(node2.InitByIdLookup(node_id2)); | 1831 EXPECT_TRUE(node2.InitByIdLookup(node_id2)); |
1834 | 1832 |
1835 sync_pb::EntitySpecifics entity_specifics2; | 1833 sync_pb::EntitySpecifics entity_specifics2; |
1836 entity_specifics2.MutableExtension(sync_pb::bookmark)->set_url(url2); | 1834 entity_specifics2.mutable_bookmark()->set_url(url2); |
1837 node2.SetEntitySpecifics(entity_specifics2); | 1835 node2.SetEntitySpecifics(entity_specifics2); |
1838 | 1836 |
1839 // Set the old style title. | 1837 // Set the old style title. |
1840 syncable::MutableEntry* node_entry2 = node2.entry_; | 1838 syncable::MutableEntry* node_entry2 = node2.entry_; |
1841 node_entry2->Put(syncable::NON_UNIQUE_NAME, title2); | 1839 node_entry2->Put(syncable::NON_UNIQUE_NAME, title2); |
1842 } | 1840 } |
1843 | 1841 |
1844 { | 1842 { |
1845 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1843 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
1846 ReadNode node(&trans); | 1844 ReadNode node(&trans); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1932 EXPECT_EQ(title, node.GetTitle()); | 1930 EXPECT_EQ(title, node.GetTitle()); |
1933 EXPECT_EQ(url, node.GetURL()); | 1931 EXPECT_EQ(url, node.GetURL()); |
1934 } | 1932 } |
1935 } | 1933 } |
1936 | 1934 |
1937 // Verifies WriteNode::UpdateEntryWithEncryption does not make unnecessary | 1935 // Verifies WriteNode::UpdateEntryWithEncryption does not make unnecessary |
1938 // changes. | 1936 // changes. |
1939 TEST_F(SyncManagerTest, UpdateEntryWithEncryption) { | 1937 TEST_F(SyncManagerTest, UpdateEntryWithEncryption) { |
1940 std::string client_tag = "title"; | 1938 std::string client_tag = "title"; |
1941 sync_pb::EntitySpecifics entity_specifics; | 1939 sync_pb::EntitySpecifics entity_specifics; |
1942 entity_specifics.MutableExtension(sync_pb::bookmark)->set_url("url"); | 1940 entity_specifics.mutable_bookmark()->set_url("url"); |
1943 entity_specifics.MutableExtension(sync_pb::bookmark)->set_title("title"); | 1941 entity_specifics.mutable_bookmark()->set_title("title"); |
1944 MakeServerNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, client_tag, | 1942 MakeServerNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, client_tag, |
1945 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, | 1943 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, |
1946 client_tag), | 1944 client_tag), |
1947 entity_specifics); | 1945 entity_specifics); |
1948 // New node shouldn't start off unsynced. | 1946 // New node shouldn't start off unsynced. |
1949 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); | 1947 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); |
1950 // Manually change to the same data. Should not set is_unsynced. | 1948 // Manually change to the same data. Should not set is_unsynced. |
1951 { | 1949 { |
1952 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1950 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
1953 WriteNode node(&trans); | 1951 WriteNode node(&trans); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2041 EXPECT_FALSE(node_entry->Get(IS_UNSYNCED)); | 2039 EXPECT_FALSE(node_entry->Get(IS_UNSYNCED)); |
2042 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2040 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
2043 Cryptographer* cryptographer = trans.GetCryptographer(); | 2041 Cryptographer* cryptographer = trans.GetCryptographer(); |
2044 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 2042 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( |
2045 specifics.encrypted())); | 2043 specifics.encrypted())); |
2046 } | 2044 } |
2047 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); | 2045 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); |
2048 | 2046 |
2049 // Manually change to different data. Should set is_unsynced. | 2047 // Manually change to different data. Should set is_unsynced. |
2050 { | 2048 { |
2051 entity_specifics.MutableExtension(sync_pb::bookmark)->set_url("url2"); | 2049 entity_specifics.mutable_bookmark()->set_url("url2"); |
2052 entity_specifics.MutableExtension(sync_pb::bookmark)->set_title("title2"); | 2050 entity_specifics.mutable_bookmark()->set_title("title2"); |
2053 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2051 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
2054 WriteNode node(&trans); | 2052 WriteNode node(&trans); |
2055 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); | 2053 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, client_tag)); |
2056 node.SetEntitySpecifics(entity_specifics); | 2054 node.SetEntitySpecifics(entity_specifics); |
2057 const syncable::Entry* node_entry = node.GetEntry(); | 2055 const syncable::Entry* node_entry = node.GetEntry(); |
2058 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2056 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
2059 EXPECT_TRUE(specifics.has_encrypted()); | 2057 EXPECT_TRUE(specifics.has_encrypted()); |
2060 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED)); | 2058 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED)); |
2061 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2059 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
2062 Cryptographer* cryptographer = trans.GetCryptographer(); | 2060 Cryptographer* cryptographer = trans.GetCryptographer(); |
2063 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 2061 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( |
2064 specifics.encrypted())); | 2062 specifics.encrypted())); |
2065 } | 2063 } |
2066 } | 2064 } |
2067 | 2065 |
2068 // Passwords have their own handling for encryption. Verify it does not result | 2066 // Passwords have their own handling for encryption. Verify it does not result |
2069 // in unnecessary writes via SetEntitySpecifics. | 2067 // in unnecessary writes via SetEntitySpecifics. |
2070 TEST_F(SyncManagerTest, UpdatePasswordSetEntitySpecificsNoChange) { | 2068 TEST_F(SyncManagerTest, UpdatePasswordSetEntitySpecificsNoChange) { |
2071 std::string client_tag = "title"; | 2069 std::string client_tag = "title"; |
2072 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2070 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
2073 sync_pb::EntitySpecifics entity_specifics; | 2071 sync_pb::EntitySpecifics entity_specifics; |
2074 { | 2072 { |
2075 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2073 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
2076 Cryptographer* cryptographer = trans.GetCryptographer(); | 2074 Cryptographer* cryptographer = trans.GetCryptographer(); |
2077 sync_pb::PasswordSpecificsData data; | 2075 sync_pb::PasswordSpecificsData data; |
2078 data.set_password_value("secret"); | 2076 data.set_password_value("secret"); |
2079 cryptographer->Encrypt( | 2077 cryptographer->Encrypt( |
2080 data, | 2078 data, |
2081 entity_specifics.MutableExtension(sync_pb::password)-> | 2079 entity_specifics.mutable_password()-> |
2082 mutable_encrypted()); | 2080 mutable_encrypted()); |
2083 } | 2081 } |
2084 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag, | 2082 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag, |
2085 BaseNode::GenerateSyncableHash(syncable::PASSWORDS, | 2083 BaseNode::GenerateSyncableHash(syncable::PASSWORDS, |
2086 client_tag), | 2084 client_tag), |
2087 entity_specifics); | 2085 entity_specifics); |
2088 // New node shouldn't start off unsynced. | 2086 // New node shouldn't start off unsynced. |
2089 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); | 2087 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); |
2090 | 2088 |
2091 // Manually change to the same data via SetEntitySpecifics. Should not set | 2089 // Manually change to the same data via SetEntitySpecifics. Should not set |
(...skipping 13 matching lines...) Expand all Loading... |
2105 std::string client_tag = "title"; | 2103 std::string client_tag = "title"; |
2106 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2104 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
2107 sync_pb::EntitySpecifics entity_specifics; | 2105 sync_pb::EntitySpecifics entity_specifics; |
2108 { | 2106 { |
2109 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2107 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
2110 Cryptographer* cryptographer = trans.GetCryptographer(); | 2108 Cryptographer* cryptographer = trans.GetCryptographer(); |
2111 sync_pb::PasswordSpecificsData data; | 2109 sync_pb::PasswordSpecificsData data; |
2112 data.set_password_value("secret"); | 2110 data.set_password_value("secret"); |
2113 cryptographer->Encrypt( | 2111 cryptographer->Encrypt( |
2114 data, | 2112 data, |
2115 entity_specifics.MutableExtension(sync_pb::password)-> | 2113 entity_specifics.mutable_password()-> |
2116 mutable_encrypted()); | 2114 mutable_encrypted()); |
2117 } | 2115 } |
2118 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag, | 2116 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag, |
2119 BaseNode::GenerateSyncableHash(syncable::PASSWORDS, | 2117 BaseNode::GenerateSyncableHash(syncable::PASSWORDS, |
2120 client_tag), | 2118 client_tag), |
2121 entity_specifics); | 2119 entity_specifics); |
2122 // New node shouldn't start off unsynced. | 2120 // New node shouldn't start off unsynced. |
2123 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); | 2121 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); |
2124 | 2122 |
2125 // Manually change to the same data via SetPasswordSpecifics. Should not set | 2123 // Manually change to the same data via SetPasswordSpecifics. Should not set |
2126 // is_unsynced. | 2124 // is_unsynced. |
2127 { | 2125 { |
2128 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2126 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
2129 WriteNode node(&trans); | 2127 WriteNode node(&trans); |
2130 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); | 2128 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); |
2131 node.SetPasswordSpecifics(node.GetPasswordSpecifics()); | 2129 node.SetPasswordSpecifics(node.GetPasswordSpecifics()); |
2132 } | 2130 } |
2133 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); | 2131 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); |
2134 | 2132 |
2135 // Manually change to different data. Should set is_unsynced. | 2133 // Manually change to different data. Should set is_unsynced. |
2136 { | 2134 { |
2137 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2135 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
2138 WriteNode node(&trans); | 2136 WriteNode node(&trans); |
2139 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); | 2137 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag)); |
2140 Cryptographer* cryptographer = trans.GetCryptographer(); | 2138 Cryptographer* cryptographer = trans.GetCryptographer(); |
2141 sync_pb::PasswordSpecificsData data; | 2139 sync_pb::PasswordSpecificsData data; |
2142 data.set_password_value("secret2"); | 2140 data.set_password_value("secret2"); |
2143 cryptographer->Encrypt( | 2141 cryptographer->Encrypt( |
2144 data, | 2142 data, |
2145 entity_specifics.MutableExtension(sync_pb::password)-> | 2143 entity_specifics.mutable_password()->mutable_encrypted()); |
2146 mutable_encrypted()); | |
2147 node.SetPasswordSpecifics(data); | 2144 node.SetPasswordSpecifics(data); |
2148 const syncable::Entry* node_entry = node.GetEntry(); | 2145 const syncable::Entry* node_entry = node.GetEntry(); |
2149 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED)); | 2146 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED)); |
2150 } | 2147 } |
2151 } | 2148 } |
2152 | 2149 |
2153 // Passwords have their own handling for encryption. Verify setting a new | 2150 // Passwords have their own handling for encryption. Verify setting a new |
2154 // passphrase updates the data. | 2151 // passphrase updates the data. |
2155 TEST_F(SyncManagerTest, UpdatePasswordNewPassphrase) { | 2152 TEST_F(SyncManagerTest, UpdatePasswordNewPassphrase) { |
2156 std::string client_tag = "title"; | 2153 std::string client_tag = "title"; |
2157 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2154 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
2158 sync_pb::EntitySpecifics entity_specifics; | 2155 sync_pb::EntitySpecifics entity_specifics; |
2159 { | 2156 { |
2160 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2157 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
2161 Cryptographer* cryptographer = trans.GetCryptographer(); | 2158 Cryptographer* cryptographer = trans.GetCryptographer(); |
2162 sync_pb::PasswordSpecificsData data; | 2159 sync_pb::PasswordSpecificsData data; |
2163 data.set_password_value("secret"); | 2160 data.set_password_value("secret"); |
2164 cryptographer->Encrypt( | 2161 cryptographer->Encrypt( |
2165 data, | 2162 data, |
2166 entity_specifics.MutableExtension(sync_pb::password)-> | 2163 entity_specifics.mutable_password()->mutable_encrypted()); |
2167 mutable_encrypted()); | |
2168 } | 2164 } |
2169 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag, | 2165 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag, |
2170 BaseNode::GenerateSyncableHash(syncable::PASSWORDS, | 2166 BaseNode::GenerateSyncableHash(syncable::PASSWORDS, |
2171 client_tag), | 2167 client_tag), |
2172 entity_specifics); | 2168 entity_specifics); |
2173 // New node shouldn't start off unsynced. | 2169 // New node shouldn't start off unsynced. |
2174 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); | 2170 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); |
2175 | 2171 |
2176 // Set a new passphrase. Should set is_unsynced. | 2172 // Set a new passphrase. Should set is_unsynced. |
2177 testing::Mock::VerifyAndClearExpectations(&observer_); | 2173 testing::Mock::VerifyAndClearExpectations(&observer_); |
(...skipping 10 matching lines...) Expand all Loading... |
2188 std::string client_tag = "title"; | 2184 std::string client_tag = "title"; |
2189 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2185 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
2190 sync_pb::EntitySpecifics entity_specifics; | 2186 sync_pb::EntitySpecifics entity_specifics; |
2191 { | 2187 { |
2192 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2188 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
2193 Cryptographer* cryptographer = trans.GetCryptographer(); | 2189 Cryptographer* cryptographer = trans.GetCryptographer(); |
2194 sync_pb::PasswordSpecificsData data; | 2190 sync_pb::PasswordSpecificsData data; |
2195 data.set_password_value("secret"); | 2191 data.set_password_value("secret"); |
2196 cryptographer->Encrypt( | 2192 cryptographer->Encrypt( |
2197 data, | 2193 data, |
2198 entity_specifics.MutableExtension(sync_pb::password)-> | 2194 entity_specifics.mutable_password()->mutable_encrypted()); |
2199 mutable_encrypted()); | |
2200 } | 2195 } |
2201 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag, | 2196 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag, |
2202 BaseNode::GenerateSyncableHash(syncable::PASSWORDS, | 2197 BaseNode::GenerateSyncableHash(syncable::PASSWORDS, |
2203 client_tag), | 2198 client_tag), |
2204 entity_specifics); | 2199 entity_specifics); |
2205 // New node shouldn't start off unsynced. | 2200 // New node shouldn't start off unsynced. |
2206 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); | 2201 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); |
2207 | 2202 |
2208 // Force a re-encrypt everything. Should not set is_unsynced. | 2203 // Force a re-encrypt everything. Should not set is_unsynced. |
2209 testing::Mock::VerifyAndClearExpectations(&observer_); | 2204 testing::Mock::VerifyAndClearExpectations(&observer_); |
2210 EXPECT_CALL(observer_, OnEncryptionComplete()); | 2205 EXPECT_CALL(observer_, OnEncryptionComplete()); |
2211 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, | 2206 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure, |
2212 base::Unretained(this))); | 2207 base::Unretained(this))); |
2213 scoped_refptr<base::ThreadTestHelper> helper( | 2208 scoped_refptr<base::ThreadTestHelper> helper( |
2214 new base::ThreadTestHelper( | 2209 new base::ThreadTestHelper( |
2215 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); | 2210 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); |
2216 ASSERT_TRUE(helper->Run()); | 2211 ASSERT_TRUE(helper->Run()); |
2217 PumpLoop(); | 2212 PumpLoop(); |
2218 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); | 2213 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag)); |
2219 } | 2214 } |
2220 | 2215 |
2221 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for bookmarks | 2216 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for bookmarks |
2222 // when we write the same data, but does set it when we write new data. | 2217 // when we write the same data, but does set it when we write new data. |
2223 TEST_F(SyncManagerTest, SetBookmarkTitle) { | 2218 TEST_F(SyncManagerTest, SetBookmarkTitle) { |
2224 std::string client_tag = "title"; | 2219 std::string client_tag = "title"; |
2225 sync_pb::EntitySpecifics entity_specifics; | 2220 sync_pb::EntitySpecifics entity_specifics; |
2226 entity_specifics.MutableExtension(sync_pb::bookmark)->set_url("url"); | 2221 entity_specifics.mutable_bookmark()->set_url("url"); |
2227 entity_specifics.MutableExtension(sync_pb::bookmark)->set_title("title"); | 2222 entity_specifics.mutable_bookmark()->set_title("title"); |
2228 MakeServerNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, client_tag, | 2223 MakeServerNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, client_tag, |
2229 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, | 2224 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, |
2230 client_tag), | 2225 client_tag), |
2231 entity_specifics); | 2226 entity_specifics); |
2232 // New node shouldn't start off unsynced. | 2227 // New node shouldn't start off unsynced. |
2233 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); | 2228 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); |
2234 | 2229 |
2235 // Manually change to the same title. Should not set is_unsynced. | 2230 // Manually change to the same title. Should not set is_unsynced. |
2236 { | 2231 { |
2237 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2232 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
(...skipping 12 matching lines...) Expand all Loading... |
2250 } | 2245 } |
2251 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); | 2246 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); |
2252 } | 2247 } |
2253 | 2248 |
2254 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted | 2249 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted |
2255 // bookmarks when we write the same data, but does set it when we write new | 2250 // bookmarks when we write the same data, but does set it when we write new |
2256 // data. | 2251 // data. |
2257 TEST_F(SyncManagerTest, SetBookmarkTitleWithEncryption) { | 2252 TEST_F(SyncManagerTest, SetBookmarkTitleWithEncryption) { |
2258 std::string client_tag = "title"; | 2253 std::string client_tag = "title"; |
2259 sync_pb::EntitySpecifics entity_specifics; | 2254 sync_pb::EntitySpecifics entity_specifics; |
2260 entity_specifics.MutableExtension(sync_pb::bookmark)->set_url("url"); | 2255 entity_specifics.mutable_bookmark()->set_url("url"); |
2261 entity_specifics.MutableExtension(sync_pb::bookmark)->set_title("title"); | 2256 entity_specifics.mutable_bookmark()->set_title("title"); |
2262 MakeServerNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, client_tag, | 2257 MakeServerNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, client_tag, |
2263 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, | 2258 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, |
2264 client_tag), | 2259 client_tag), |
2265 entity_specifics); | 2260 entity_specifics); |
2266 // New node shouldn't start off unsynced. | 2261 // New node shouldn't start off unsynced. |
2267 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); | 2262 EXPECT_FALSE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); |
2268 | 2263 |
2269 // Encrypt the datatatype, should set is_unsynced. | 2264 // Encrypt the datatatype, should set is_unsynced. |
2270 EXPECT_CALL(observer_, | 2265 EXPECT_CALL(observer_, |
2271 OnEncryptedTypesChanged( | 2266 OnEncryptedTypesChanged( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2308 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2303 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
2309 } | 2304 } |
2310 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); | 2305 EXPECT_TRUE(ResetUnsyncedEntry(syncable::BOOKMARKS, client_tag)); |
2311 } | 2306 } |
2312 | 2307 |
2313 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for non-bookmarks | 2308 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for non-bookmarks |
2314 // when we write the same data, but does set it when we write new data. | 2309 // when we write the same data, but does set it when we write new data. |
2315 TEST_F(SyncManagerTest, SetNonBookmarkTitle) { | 2310 TEST_F(SyncManagerTest, SetNonBookmarkTitle) { |
2316 std::string client_tag = "title"; | 2311 std::string client_tag = "title"; |
2317 sync_pb::EntitySpecifics entity_specifics; | 2312 sync_pb::EntitySpecifics entity_specifics; |
2318 entity_specifics.MutableExtension(sync_pb::preference)->set_name("name"); | 2313 entity_specifics.mutable_preference()->set_name("name"); |
2319 entity_specifics.MutableExtension(sync_pb::preference)->set_value("value"); | 2314 entity_specifics.mutable_preference()->set_value("value"); |
2320 MakeServerNode(sync_manager_.GetUserShare(), | 2315 MakeServerNode(sync_manager_.GetUserShare(), |
2321 syncable::PREFERENCES, | 2316 syncable::PREFERENCES, |
2322 client_tag, | 2317 client_tag, |
2323 BaseNode::GenerateSyncableHash(syncable::PREFERENCES, | 2318 BaseNode::GenerateSyncableHash(syncable::PREFERENCES, |
2324 client_tag), | 2319 client_tag), |
2325 entity_specifics); | 2320 entity_specifics); |
2326 // New node shouldn't start off unsynced. | 2321 // New node shouldn't start off unsynced. |
2327 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); | 2322 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); |
2328 | 2323 |
2329 // Manually change to the same title. Should not set is_unsynced. | 2324 // Manually change to the same title. Should not set is_unsynced. |
(...skipping 14 matching lines...) Expand all Loading... |
2344 } | 2339 } |
2345 EXPECT_TRUE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); | 2340 EXPECT_TRUE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); |
2346 } | 2341 } |
2347 | 2342 |
2348 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted | 2343 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted |
2349 // non-bookmarks when we write the same data or when we write new data | 2344 // non-bookmarks when we write the same data or when we write new data |
2350 // data (should remained kEncryptedString). | 2345 // data (should remained kEncryptedString). |
2351 TEST_F(SyncManagerTest, SetNonBookmarkTitleWithEncryption) { | 2346 TEST_F(SyncManagerTest, SetNonBookmarkTitleWithEncryption) { |
2352 std::string client_tag = "title"; | 2347 std::string client_tag = "title"; |
2353 sync_pb::EntitySpecifics entity_specifics; | 2348 sync_pb::EntitySpecifics entity_specifics; |
2354 entity_specifics.MutableExtension(sync_pb::preference)->set_name("name"); | 2349 entity_specifics.mutable_preference()->set_name("name"); |
2355 entity_specifics.MutableExtension(sync_pb::preference)->set_value("value"); | 2350 entity_specifics.mutable_preference()->set_value("value"); |
2356 MakeServerNode(sync_manager_.GetUserShare(), | 2351 MakeServerNode(sync_manager_.GetUserShare(), |
2357 syncable::PREFERENCES, | 2352 syncable::PREFERENCES, |
2358 client_tag, | 2353 client_tag, |
2359 BaseNode::GenerateSyncableHash(syncable::PREFERENCES, | 2354 BaseNode::GenerateSyncableHash(syncable::PREFERENCES, |
2360 client_tag), | 2355 client_tag), |
2361 entity_specifics); | 2356 entity_specifics); |
2362 // New node shouldn't start off unsynced. | 2357 // New node shouldn't start off unsynced. |
2363 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); | 2358 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PREFERENCES, client_tag)); |
2364 | 2359 |
2365 // Encrypt the datatatype, should set is_unsynced. | 2360 // Encrypt the datatatype, should set is_unsynced. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2413 std::string client_tag = "tag"; | 2408 std::string client_tag = "tag"; |
2414 std::string url = "url"; | 2409 std::string url = "url"; |
2415 std::string url2 = "new_url"; | 2410 std::string url2 = "new_url"; |
2416 std::string title = "title"; | 2411 std::string title = "title"; |
2417 sync_pb::EntitySpecifics entity_specifics; | 2412 sync_pb::EntitySpecifics entity_specifics; |
2418 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2413 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
2419 { | 2414 { |
2420 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2415 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
2421 browser_sync::Cryptographer* crypto = trans.GetCryptographer(); | 2416 browser_sync::Cryptographer* crypto = trans.GetCryptographer(); |
2422 sync_pb::EntitySpecifics bm_specifics; | 2417 sync_pb::EntitySpecifics bm_specifics; |
2423 bm_specifics.MutableExtension(sync_pb::bookmark)->set_title("title"); | 2418 bm_specifics.mutable_bookmark()->set_title("title"); |
2424 bm_specifics.MutableExtension(sync_pb::bookmark)->set_url("url"); | 2419 bm_specifics.mutable_bookmark()->set_url("url"); |
2425 sync_pb::EncryptedData encrypted; | 2420 sync_pb::EncryptedData encrypted; |
2426 crypto->Encrypt(bm_specifics, &encrypted); | 2421 crypto->Encrypt(bm_specifics, &encrypted); |
2427 entity_specifics.mutable_encrypted()->CopyFrom(encrypted); | 2422 entity_specifics.mutable_encrypted()->CopyFrom(encrypted); |
2428 syncable::AddDefaultExtensionValue(syncable::BOOKMARKS, &entity_specifics); | 2423 syncable::AddDefaultExtensionValue(syncable::BOOKMARKS, &entity_specifics); |
2429 } | 2424 } |
2430 MakeServerNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, client_tag, | 2425 MakeServerNode(sync_manager_.GetUserShare(), syncable::BOOKMARKS, client_tag, |
2431 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, | 2426 BaseNode::GenerateSyncableHash(syncable::BOOKMARKS, |
2432 client_tag), | 2427 client_tag), |
2433 entity_specifics); | 2428 entity_specifics); |
2434 | 2429 |
(...skipping 22 matching lines...) Expand all Loading... |
2457 EXPECT_EQ(title, node.GetTitle()); | 2452 EXPECT_EQ(title, node.GetTitle()); |
2458 EXPECT_EQ(GURL(url2), node.GetURL()); | 2453 EXPECT_EQ(GURL(url2), node.GetURL()); |
2459 const syncable::Entry* node_entry = node.GetEntry(); | 2454 const syncable::Entry* node_entry = node.GetEntry(); |
2460 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2455 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
2461 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2456 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
2462 EXPECT_TRUE(specifics.has_encrypted()); | 2457 EXPECT_TRUE(specifics.has_encrypted()); |
2463 } | 2458 } |
2464 } | 2459 } |
2465 | 2460 |
2466 } // namespace browser_sync | 2461 } // namespace browser_sync |
OLD | NEW |