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

Side by Side Diff: chrome/browser/sync/internal_api/syncapi_unittest.cc

Issue 9315048: [Sync] Fix idempotency check for passwords datatype. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 10 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 2010 matching lines...) Expand 10 before | Expand all | Expand 10 after
2021 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); 2021 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS);
2022 EXPECT_TRUE(specifics.has_encrypted()); 2022 EXPECT_TRUE(specifics.has_encrypted());
2023 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED)); 2023 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED));
2024 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); 2024 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME));
2025 Cryptographer* cryptographer = trans.GetCryptographer(); 2025 Cryptographer* cryptographer = trans.GetCryptographer();
2026 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( 2026 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey(
2027 specifics.encrypted())); 2027 specifics.encrypted()));
2028 } 2028 }
2029 } 2029 }
2030 2030
2031 // Passwords have their own handling for encryption. Verify it does not result
2032 // in unnecessary writes via SetEntitySpecifics.
2033 TEST_F(SyncManagerTest, UpdatePasswordSetEntitySpecificsNoChange) {
2034 std::string client_tag = "title";
2035 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
2036 sync_pb::EntitySpecifics entity_specifics;
2037 {
2038 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2039 Cryptographer* cryptographer = trans.GetCryptographer();
2040 sync_pb::PasswordSpecificsData data;
2041 data.set_password_value("secret");
2042 cryptographer->Encrypt(
2043 data,
2044 entity_specifics.MutableExtension(sync_pb::password)->
2045 mutable_encrypted());
2046 }
2047 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag,
2048 BaseNode::GenerateSyncableHash(syncable::PASSWORDS,
2049 client_tag),
2050 entity_specifics);
2051 // New node shouldn't start off unsynced.
2052 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag));
2053
2054 // Manually change to the same data via SetEntitySpecifics. Should not set
2055 // is_unsynced.
2056 {
2057 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2058 WriteNode node(&trans);
2059 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag));
2060 node.SetEntitySpecifics(entity_specifics);
2061 }
2062 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag));
2063 }
2064
2065 // Passwords have their own handling for encryption. Verify it does not result
2066 // in unnecessary writes via SetPasswordSpecifics.
2067 TEST_F(SyncManagerTest, UpdatePasswordSetPasswordSpecifics) {
2068 std::string client_tag = "title";
2069 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
2070 sync_pb::EntitySpecifics entity_specifics;
2071 {
2072 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2073 Cryptographer* cryptographer = trans.GetCryptographer();
2074 sync_pb::PasswordSpecificsData data;
2075 data.set_password_value("secret");
2076 cryptographer->Encrypt(
2077 data,
2078 entity_specifics.MutableExtension(sync_pb::password)->
2079 mutable_encrypted());
2080 }
2081 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag,
2082 BaseNode::GenerateSyncableHash(syncable::PASSWORDS,
2083 client_tag),
2084 entity_specifics);
2085 // New node shouldn't start off unsynced.
2086 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag));
2087
2088 // Manually change to the same data via SetPasswordSpecifics. Should not set
2089 // is_unsynced.
2090 {
2091 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2092 WriteNode node(&trans);
2093 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag));
2094 node.SetPasswordSpecifics(node.GetPasswordSpecifics());
2095 }
2096 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag));
2097
2098 // Manually change to different data. Should set is_unsynced.
2099 {
2100 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2101 WriteNode node(&trans);
2102 EXPECT_TRUE(node.InitByClientTagLookup(syncable::PASSWORDS, client_tag));
2103 Cryptographer* cryptographer = trans.GetCryptographer();
2104 sync_pb::PasswordSpecificsData data;
2105 data.set_password_value("secret2");
2106 cryptographer->Encrypt(
2107 data,
2108 entity_specifics.MutableExtension(sync_pb::password)->
2109 mutable_encrypted());
2110 node.SetPasswordSpecifics(data);
2111 const syncable::Entry* node_entry = node.GetEntry();
2112 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED));
2113 }
2114 }
2115
2116 // Passwords have their own handling for encryption. Verify setting a new
2117 // passphrase updates the data.
2118 TEST_F(SyncManagerTest, UpdatePasswordNewPassphrase) {
2119 std::string client_tag = "title";
2120 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
2121 sync_pb::EntitySpecifics entity_specifics;
2122 {
2123 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2124 Cryptographer* cryptographer = trans.GetCryptographer();
2125 sync_pb::PasswordSpecificsData data;
2126 data.set_password_value("secret");
2127 cryptographer->Encrypt(
2128 data,
2129 entity_specifics.MutableExtension(sync_pb::password)->
2130 mutable_encrypted());
2131 }
2132 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag,
2133 BaseNode::GenerateSyncableHash(syncable::PASSWORDS,
2134 client_tag),
2135 entity_specifics);
2136 // New node shouldn't start off unsynced.
2137 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag));
2138
2139 // Set a new passphrase. Should set is_unsynced.
2140 testing::Mock::VerifyAndClearExpectations(&observer_);
2141 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_));
2142 EXPECT_CALL(observer_, OnPassphraseAccepted());
2143 EXPECT_CALL(observer_, OnEncryptionComplete());
2144 sync_manager_.SetPassphrase("new_passphrase", true, true);
2145 EXPECT_TRUE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag));
2146 }
2147
2148 // Passwords have their own handling for encryption. Verify it does not result
2149 // in unnecessary writes via ReencryptEverything.
2150 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) {
2151 std::string client_tag = "title";
2152 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
2153 sync_pb::EntitySpecifics entity_specifics;
2154 {
2155 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2156 Cryptographer* cryptographer = trans.GetCryptographer();
2157 sync_pb::PasswordSpecificsData data;
2158 data.set_password_value("secret");
2159 cryptographer->Encrypt(
2160 data,
2161 entity_specifics.MutableExtension(sync_pb::password)->
2162 mutable_encrypted());
2163 }
2164 MakeServerNode(sync_manager_.GetUserShare(), syncable::PASSWORDS, client_tag,
2165 BaseNode::GenerateSyncableHash(syncable::PASSWORDS,
2166 client_tag),
2167 entity_specifics);
2168 // New node shouldn't start off unsynced.
2169 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag));
2170
2171 // Force a re-encrypt everything. Should not set is_unsynced.
2172 testing::Mock::VerifyAndClearExpectations(&observer_);
2173 EXPECT_CALL(observer_, OnEncryptionComplete());
2174 sync_manager_.RefreshNigori(base::Bind(&SyncManagerTest::EmptyClosure,
2175 base::Unretained(this)));
2176 scoped_refptr<base::ThreadTestHelper> helper(
2177 new base::ThreadTestHelper(
2178 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)));
2179 ASSERT_TRUE(helper->Run());
2180 PumpLoop();
2181 EXPECT_FALSE(ResetUnsyncedEntry(syncable::PASSWORDS, client_tag));
2182 }
2183
2031 } // namespace browser_sync 2184 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/internal_api/base_node.h ('k') | chrome/browser/sync/internal_api/write_node.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698