| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 EXPECT_TRUE(value.GetString(key, &int64_str)); | 102 EXPECT_TRUE(value.GetString(key, &int64_str)); |
| 103 int64 val = 0; | 103 int64 val = 0; |
| 104 EXPECT_TRUE(base::StringToInt64(int64_str, &val)); | 104 EXPECT_TRUE(base::StringToInt64(int64_str, &val)); |
| 105 EXPECT_EQ(expected_value, val); | 105 EXPECT_EQ(expected_value, val); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void ExpectTimeValue(const base::Time& expected_value, | 108 void ExpectTimeValue(const base::Time& expected_value, |
| 109 const DictionaryValue& value, const std::string& key) { | 109 const DictionaryValue& value, const std::string& key) { |
| 110 std::string time_str; | 110 std::string time_str; |
| 111 EXPECT_TRUE(value.GetString(key, &time_str)); | 111 EXPECT_TRUE(value.GetString(key, &time_str)); |
| 112 EXPECT_EQ(syncer::GetTimeDebugString(expected_value), time_str); | 112 EXPECT_EQ(GetTimeDebugString(expected_value), time_str); |
| 113 } | 113 } |
| 114 | 114 |
| 115 // Makes a non-folder child of the root node. Returns the id of the | 115 // Makes a non-folder child of the root node. Returns the id of the |
| 116 // newly-created node. | 116 // newly-created node. |
| 117 int64 MakeNode(UserShare* share, | 117 int64 MakeNode(UserShare* share, |
| 118 ModelType model_type, | 118 ModelType model_type, |
| 119 const std::string& client_tag) { | 119 const std::string& client_tag) { |
| 120 WriteTransaction trans(FROM_HERE, share); | 120 WriteTransaction trans(FROM_HERE, share); |
| 121 ReadNode root_node(&trans); | 121 ReadNode root_node(&trans); |
| 122 root_node.InitByRootLookup(); | 122 root_node.InitByRootLookup(); |
| 123 WriteNode node(&trans); | 123 WriteNode node(&trans); |
| 124 syncer::WriteNode::InitUniqueByCreationResult result = | 124 WriteNode::InitUniqueByCreationResult result = |
| 125 node.InitUniqueByCreation(model_type, root_node, client_tag); | 125 node.InitUniqueByCreation(model_type, root_node, client_tag); |
| 126 EXPECT_EQ(syncer::WriteNode::INIT_SUCCESS, result); | 126 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 127 node.SetIsFolder(false); | 127 node.SetIsFolder(false); |
| 128 return node.GetId(); | 128 return node.GetId(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 // Makes a non-folder child of a non-root node. Returns the id of the | 131 // Makes a non-folder child of a non-root node. Returns the id of the |
| 132 // newly-created node. | 132 // newly-created node. |
| 133 int64 MakeNodeWithParent(UserShare* share, | 133 int64 MakeNodeWithParent(UserShare* share, |
| 134 ModelType model_type, | 134 ModelType model_type, |
| 135 const std::string& client_tag, | 135 const std::string& client_tag, |
| 136 int64 parent_id) { | 136 int64 parent_id) { |
| 137 WriteTransaction trans(FROM_HERE, share); | 137 WriteTransaction trans(FROM_HERE, share); |
| 138 ReadNode parent_node(&trans); | 138 ReadNode parent_node(&trans); |
| 139 EXPECT_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id)); | 139 EXPECT_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id)); |
| 140 WriteNode node(&trans); | 140 WriteNode node(&trans); |
| 141 syncer::WriteNode::InitUniqueByCreationResult result = | 141 WriteNode::InitUniqueByCreationResult result = |
| 142 node.InitUniqueByCreation(model_type, parent_node, client_tag); | 142 node.InitUniqueByCreation(model_type, parent_node, client_tag); |
| 143 EXPECT_EQ(syncer::WriteNode::INIT_SUCCESS, result); | 143 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 144 node.SetIsFolder(false); | 144 node.SetIsFolder(false); |
| 145 return node.GetId(); | 145 return node.GetId(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 // Makes a folder child of a non-root node. Returns the id of the | 148 // Makes a folder child of a non-root node. Returns the id of the |
| 149 // newly-created node. | 149 // newly-created node. |
| 150 int64 MakeFolderWithParent(UserShare* share, | 150 int64 MakeFolderWithParent(UserShare* share, |
| 151 ModelType model_type, | 151 ModelType model_type, |
| 152 int64 parent_id, | 152 int64 parent_id, |
| 153 BaseNode* predecessor) { | 153 BaseNode* predecessor) { |
| 154 WriteTransaction trans(FROM_HERE, share); | 154 WriteTransaction trans(FROM_HERE, share); |
| 155 ReadNode parent_node(&trans); | 155 ReadNode parent_node(&trans); |
| 156 EXPECT_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id)); | 156 EXPECT_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id)); |
| 157 WriteNode node(&trans); | 157 WriteNode node(&trans); |
| 158 EXPECT_TRUE(node.InitByCreation(model_type, parent_node, predecessor)); | 158 EXPECT_TRUE(node.InitByCreation(model_type, parent_node, predecessor)); |
| 159 node.SetIsFolder(true); | 159 node.SetIsFolder(true); |
| 160 return node.GetId(); | 160 return node.GetId(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 // Creates the "synced" root node for a particular datatype. We use the syncable | 163 // Creates the "synced" root node for a particular datatype. We use the syncable |
| 164 // methods here so that the syncer treats these nodes as if they were already | 164 // methods here so that the syncer treats these nodes as if they were already |
| 165 // received from the server. | 165 // received from the server. |
| 166 int64 MakeServerNodeForType(UserShare* share, | 166 int64 MakeServerNodeForType(UserShare* share, |
| 167 ModelType model_type) { | 167 ModelType model_type) { |
| 168 sync_pb::EntitySpecifics specifics; | 168 sync_pb::EntitySpecifics specifics; |
| 169 syncer::AddDefaultFieldValue(model_type, &specifics); | 169 AddDefaultFieldValue(model_type, &specifics); |
| 170 syncable::WriteTransaction trans( | 170 syncable::WriteTransaction trans( |
| 171 FROM_HERE, syncable::UNITTEST, share->directory.get()); | 171 FROM_HERE, syncable::UNITTEST, share->directory.get()); |
| 172 // Attempt to lookup by nigori tag. | 172 // Attempt to lookup by nigori tag. |
| 173 std::string type_tag = syncer::ModelTypeToRootTag(model_type); | 173 std::string type_tag = ModelTypeToRootTag(model_type); |
| 174 syncable::Id node_id = syncable::Id::CreateFromServerId(type_tag); | 174 syncable::Id node_id = syncable::Id::CreateFromServerId(type_tag); |
| 175 syncable::MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, | 175 syncable::MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, |
| 176 node_id); | 176 node_id); |
| 177 EXPECT_TRUE(entry.good()); | 177 EXPECT_TRUE(entry.good()); |
| 178 entry.Put(syncable::BASE_VERSION, 1); | 178 entry.Put(syncable::BASE_VERSION, 1); |
| 179 entry.Put(syncable::SERVER_VERSION, 1); | 179 entry.Put(syncable::SERVER_VERSION, 1); |
| 180 entry.Put(syncable::IS_UNAPPLIED_UPDATE, false); | 180 entry.Put(syncable::IS_UNAPPLIED_UPDATE, false); |
| 181 entry.Put(syncable::SERVER_PARENT_ID, syncable::GetNullId()); | 181 entry.Put(syncable::SERVER_PARENT_ID, syncable::GetNullId()); |
| 182 entry.Put(syncable::SERVER_IS_DIR, true); | 182 entry.Put(syncable::SERVER_IS_DIR, true); |
| 183 entry.Put(syncable::IS_DIR, true); | 183 entry.Put(syncable::IS_DIR, true); |
| 184 entry.Put(syncable::SERVER_SPECIFICS, specifics); | 184 entry.Put(syncable::SERVER_SPECIFICS, specifics); |
| 185 entry.Put(syncable::UNIQUE_SERVER_TAG, type_tag); | 185 entry.Put(syncable::UNIQUE_SERVER_TAG, type_tag); |
| 186 entry.Put(syncable::NON_UNIQUE_NAME, type_tag); | 186 entry.Put(syncable::NON_UNIQUE_NAME, type_tag); |
| 187 entry.Put(syncable::IS_DEL, false); | 187 entry.Put(syncable::IS_DEL, false); |
| 188 entry.Put(syncable::SPECIFICS, specifics); | 188 entry.Put(syncable::SPECIFICS, specifics); |
| 189 return entry.Get(syncable::META_HANDLE); | 189 return entry.Get(syncable::META_HANDLE); |
| 190 } | 190 } |
| 191 | 191 |
| 192 // Simulates creating a "synced" node as a child of the root datatype node. | 192 // Simulates creating a "synced" node as a child of the root datatype node. |
| 193 int64 MakeServerNode(UserShare* share, ModelType model_type, | 193 int64 MakeServerNode(UserShare* share, ModelType model_type, |
| 194 const std::string& client_tag, | 194 const std::string& client_tag, |
| 195 const std::string& hashed_tag, | 195 const std::string& hashed_tag, |
| 196 const sync_pb::EntitySpecifics& specifics) { | 196 const sync_pb::EntitySpecifics& specifics) { |
| 197 syncable::WriteTransaction trans( | 197 syncable::WriteTransaction trans( |
| 198 FROM_HERE, syncable::UNITTEST, share->directory.get()); | 198 FROM_HERE, syncable::UNITTEST, share->directory.get()); |
| 199 syncable::Entry root_entry(&trans, syncable::GET_BY_SERVER_TAG, | 199 syncable::Entry root_entry(&trans, syncable::GET_BY_SERVER_TAG, |
| 200 syncer::ModelTypeToRootTag(model_type)); | 200 ModelTypeToRootTag(model_type)); |
| 201 EXPECT_TRUE(root_entry.good()); | 201 EXPECT_TRUE(root_entry.good()); |
| 202 syncable::Id root_id = root_entry.Get(syncable::ID); | 202 syncable::Id root_id = root_entry.Get(syncable::ID); |
| 203 syncable::Id node_id = syncable::Id::CreateFromServerId(client_tag); | 203 syncable::Id node_id = syncable::Id::CreateFromServerId(client_tag); |
| 204 syncable::MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, | 204 syncable::MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, |
| 205 node_id); | 205 node_id); |
| 206 EXPECT_TRUE(entry.good()); | 206 EXPECT_TRUE(entry.good()); |
| 207 entry.Put(syncable::BASE_VERSION, 1); | 207 entry.Put(syncable::BASE_VERSION, 1); |
| 208 entry.Put(syncable::SERVER_VERSION, 1); | 208 entry.Put(syncable::SERVER_VERSION, 1); |
| 209 entry.Put(syncable::IS_UNAPPLIED_UPDATE, false); | 209 entry.Put(syncable::IS_UNAPPLIED_UPDATE, false); |
| 210 entry.Put(syncable::SERVER_PARENT_ID, root_id); | 210 entry.Put(syncable::SERVER_PARENT_ID, root_id); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 226 virtual void SetUp() { | 226 virtual void SetUp() { |
| 227 test_user_share_.SetUp(); | 227 test_user_share_.SetUp(); |
| 228 } | 228 } |
| 229 | 229 |
| 230 virtual void TearDown() { | 230 virtual void TearDown() { |
| 231 test_user_share_.TearDown(); | 231 test_user_share_.TearDown(); |
| 232 } | 232 } |
| 233 | 233 |
| 234 protected: | 234 protected: |
| 235 MessageLoop message_loop_; | 235 MessageLoop message_loop_; |
| 236 syncer::TestUserShare test_user_share_; | 236 TestUserShare test_user_share_; |
| 237 }; | 237 }; |
| 238 | 238 |
| 239 TEST_F(SyncApiTest, SanityCheckTest) { | 239 TEST_F(SyncApiTest, SanityCheckTest) { |
| 240 { | 240 { |
| 241 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 241 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 242 EXPECT_TRUE(trans.GetWrappedTrans() != NULL); | 242 EXPECT_TRUE(trans.GetWrappedTrans() != NULL); |
| 243 } | 243 } |
| 244 { | 244 { |
| 245 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 245 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 246 EXPECT_TRUE(trans.GetWrappedTrans() != NULL); | 246 EXPECT_TRUE(trans.GetWrappedTrans() != NULL); |
| 247 } | 247 } |
| 248 { | 248 { |
| 249 // No entries but root should exist | 249 // No entries but root should exist |
| 250 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 250 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 251 ReadNode node(&trans); | 251 ReadNode node(&trans); |
| 252 // Metahandle 1 can be root, sanity check 2 | 252 // Metahandle 1 can be root, sanity check 2 |
| 253 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, node.InitByIdLookup(2)); | 253 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, node.InitByIdLookup(2)); |
| 254 } | 254 } |
| 255 } | 255 } |
| 256 | 256 |
| 257 TEST_F(SyncApiTest, BasicTagWrite) { | 257 TEST_F(SyncApiTest, BasicTagWrite) { |
| 258 { | 258 { |
| 259 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 259 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 260 ReadNode root_node(&trans); | 260 ReadNode root_node(&trans); |
| 261 root_node.InitByRootLookup(); | 261 root_node.InitByRootLookup(); |
| 262 EXPECT_EQ(root_node.GetFirstChildId(), 0); | 262 EXPECT_EQ(root_node.GetFirstChildId(), 0); |
| 263 } | 263 } |
| 264 | 264 |
| 265 ignore_result(MakeNode(test_user_share_.user_share(), | 265 ignore_result(MakeNode(test_user_share_.user_share(), |
| 266 syncer::BOOKMARKS, "testtag")); | 266 BOOKMARKS, "testtag")); |
| 267 | 267 |
| 268 { | 268 { |
| 269 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 269 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 270 ReadNode node(&trans); | 270 ReadNode node(&trans); |
| 271 EXPECT_EQ(BaseNode::INIT_OK, | 271 EXPECT_EQ(BaseNode::INIT_OK, |
| 272 node.InitByClientTagLookup(syncer::BOOKMARKS, "testtag")); | 272 node.InitByClientTagLookup(BOOKMARKS, "testtag")); |
| 273 | 273 |
| 274 ReadNode root_node(&trans); | 274 ReadNode root_node(&trans); |
| 275 root_node.InitByRootLookup(); | 275 root_node.InitByRootLookup(); |
| 276 EXPECT_NE(node.GetId(), 0); | 276 EXPECT_NE(node.GetId(), 0); |
| 277 EXPECT_EQ(node.GetId(), root_node.GetFirstChildId()); | 277 EXPECT_EQ(node.GetId(), root_node.GetFirstChildId()); |
| 278 } | 278 } |
| 279 } | 279 } |
| 280 | 280 |
| 281 TEST_F(SyncApiTest, GenerateSyncableHash) { | 281 TEST_F(SyncApiTest, GenerateSyncableHash) { |
| 282 EXPECT_EQ("OyaXV5mEzrPS4wbogmtKvRfekAI=", | 282 EXPECT_EQ("OyaXV5mEzrPS4wbogmtKvRfekAI=", |
| 283 BaseNode::GenerateSyncableHash(syncer::BOOKMARKS, "tag1")); | 283 BaseNode::GenerateSyncableHash(BOOKMARKS, "tag1")); |
| 284 EXPECT_EQ("iNFQtRFQb+IZcn1kKUJEZDDkLs4=", | 284 EXPECT_EQ("iNFQtRFQb+IZcn1kKUJEZDDkLs4=", |
| 285 BaseNode::GenerateSyncableHash(syncer::PREFERENCES, "tag1")); | 285 BaseNode::GenerateSyncableHash(PREFERENCES, "tag1")); |
| 286 EXPECT_EQ("gO1cPZQXaM73sHOvSA+tKCKFs58=", | 286 EXPECT_EQ("gO1cPZQXaM73sHOvSA+tKCKFs58=", |
| 287 BaseNode::GenerateSyncableHash(syncer::AUTOFILL, "tag1")); | 287 BaseNode::GenerateSyncableHash(AUTOFILL, "tag1")); |
| 288 | 288 |
| 289 EXPECT_EQ("A0eYIHXM1/jVwKDDp12Up20IkKY=", | 289 EXPECT_EQ("A0eYIHXM1/jVwKDDp12Up20IkKY=", |
| 290 BaseNode::GenerateSyncableHash(syncer::BOOKMARKS, "tag2")); | 290 BaseNode::GenerateSyncableHash(BOOKMARKS, "tag2")); |
| 291 EXPECT_EQ("XYxkF7bhS4eItStFgiOIAU23swI=", | 291 EXPECT_EQ("XYxkF7bhS4eItStFgiOIAU23swI=", |
| 292 BaseNode::GenerateSyncableHash(syncer::PREFERENCES, "tag2")); | 292 BaseNode::GenerateSyncableHash(PREFERENCES, "tag2")); |
| 293 EXPECT_EQ("GFiWzo5NGhjLlN+OyCfhy28DJTQ=", | 293 EXPECT_EQ("GFiWzo5NGhjLlN+OyCfhy28DJTQ=", |
| 294 BaseNode::GenerateSyncableHash(syncer::AUTOFILL, "tag2")); | 294 BaseNode::GenerateSyncableHash(AUTOFILL, "tag2")); |
| 295 } | 295 } |
| 296 | 296 |
| 297 TEST_F(SyncApiTest, ModelTypesSiloed) { | 297 TEST_F(SyncApiTest, ModelTypesSiloed) { |
| 298 { | 298 { |
| 299 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 299 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 300 ReadNode root_node(&trans); | 300 ReadNode root_node(&trans); |
| 301 root_node.InitByRootLookup(); | 301 root_node.InitByRootLookup(); |
| 302 EXPECT_EQ(root_node.GetFirstChildId(), 0); | 302 EXPECT_EQ(root_node.GetFirstChildId(), 0); |
| 303 } | 303 } |
| 304 | 304 |
| 305 ignore_result(MakeNode(test_user_share_.user_share(), | 305 ignore_result(MakeNode(test_user_share_.user_share(), |
| 306 syncer::BOOKMARKS, "collideme")); | 306 BOOKMARKS, "collideme")); |
| 307 ignore_result(MakeNode(test_user_share_.user_share(), | 307 ignore_result(MakeNode(test_user_share_.user_share(), |
| 308 syncer::PREFERENCES, "collideme")); | 308 PREFERENCES, "collideme")); |
| 309 ignore_result(MakeNode(test_user_share_.user_share(), | 309 ignore_result(MakeNode(test_user_share_.user_share(), |
| 310 syncer::AUTOFILL, "collideme")); | 310 AUTOFILL, "collideme")); |
| 311 | 311 |
| 312 { | 312 { |
| 313 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 313 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 314 | 314 |
| 315 ReadNode bookmarknode(&trans); | 315 ReadNode bookmarknode(&trans); |
| 316 EXPECT_EQ(BaseNode::INIT_OK, | 316 EXPECT_EQ(BaseNode::INIT_OK, |
| 317 bookmarknode.InitByClientTagLookup(syncer::BOOKMARKS, | 317 bookmarknode.InitByClientTagLookup(BOOKMARKS, |
| 318 "collideme")); | 318 "collideme")); |
| 319 | 319 |
| 320 ReadNode prefnode(&trans); | 320 ReadNode prefnode(&trans); |
| 321 EXPECT_EQ(BaseNode::INIT_OK, | 321 EXPECT_EQ(BaseNode::INIT_OK, |
| 322 prefnode.InitByClientTagLookup(syncer::PREFERENCES, | 322 prefnode.InitByClientTagLookup(PREFERENCES, |
| 323 "collideme")); | 323 "collideme")); |
| 324 | 324 |
| 325 ReadNode autofillnode(&trans); | 325 ReadNode autofillnode(&trans); |
| 326 EXPECT_EQ(BaseNode::INIT_OK, | 326 EXPECT_EQ(BaseNode::INIT_OK, |
| 327 autofillnode.InitByClientTagLookup(syncer::AUTOFILL, | 327 autofillnode.InitByClientTagLookup(AUTOFILL, |
| 328 "collideme")); | 328 "collideme")); |
| 329 | 329 |
| 330 EXPECT_NE(bookmarknode.GetId(), prefnode.GetId()); | 330 EXPECT_NE(bookmarknode.GetId(), prefnode.GetId()); |
| 331 EXPECT_NE(autofillnode.GetId(), prefnode.GetId()); | 331 EXPECT_NE(autofillnode.GetId(), prefnode.GetId()); |
| 332 EXPECT_NE(bookmarknode.GetId(), autofillnode.GetId()); | 332 EXPECT_NE(bookmarknode.GetId(), autofillnode.GetId()); |
| 333 } | 333 } |
| 334 } | 334 } |
| 335 | 335 |
| 336 TEST_F(SyncApiTest, ReadMissingTagsFails) { | 336 TEST_F(SyncApiTest, ReadMissingTagsFails) { |
| 337 { | 337 { |
| 338 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 338 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 339 ReadNode node(&trans); | 339 ReadNode node(&trans); |
| 340 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, | 340 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, |
| 341 node.InitByClientTagLookup(syncer::BOOKMARKS, | 341 node.InitByClientTagLookup(BOOKMARKS, |
| 342 "testtag")); | 342 "testtag")); |
| 343 } | 343 } |
| 344 { | 344 { |
| 345 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 345 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 346 WriteNode node(&trans); | 346 WriteNode node(&trans); |
| 347 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, | 347 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, |
| 348 node.InitByClientTagLookup(syncer::BOOKMARKS, | 348 node.InitByClientTagLookup(BOOKMARKS, |
| 349 "testtag")); | 349 "testtag")); |
| 350 } | 350 } |
| 351 } | 351 } |
| 352 | 352 |
| 353 // TODO(chron): Hook this all up to the server and write full integration tests | 353 // TODO(chron): Hook this all up to the server and write full integration tests |
| 354 // for update->undelete behavior. | 354 // for update->undelete behavior. |
| 355 TEST_F(SyncApiTest, TestDeleteBehavior) { | 355 TEST_F(SyncApiTest, TestDeleteBehavior) { |
| 356 int64 node_id; | 356 int64 node_id; |
| 357 int64 folder_id; | 357 int64 folder_id; |
| 358 std::string test_title("test1"); | 358 std::string test_title("test1"); |
| 359 | 359 |
| 360 { | 360 { |
| 361 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 361 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 362 ReadNode root_node(&trans); | 362 ReadNode root_node(&trans); |
| 363 root_node.InitByRootLookup(); | 363 root_node.InitByRootLookup(); |
| 364 | 364 |
| 365 // we'll use this spare folder later | 365 // we'll use this spare folder later |
| 366 WriteNode folder_node(&trans); | 366 WriteNode folder_node(&trans); |
| 367 EXPECT_TRUE(folder_node.InitByCreation(syncer::BOOKMARKS, | 367 EXPECT_TRUE(folder_node.InitByCreation(BOOKMARKS, |
| 368 root_node, NULL)); | 368 root_node, NULL)); |
| 369 folder_id = folder_node.GetId(); | 369 folder_id = folder_node.GetId(); |
| 370 | 370 |
| 371 WriteNode wnode(&trans); | 371 WriteNode wnode(&trans); |
| 372 syncer::WriteNode::InitUniqueByCreationResult result = | 372 WriteNode::InitUniqueByCreationResult result = |
| 373 wnode.InitUniqueByCreation(syncer::BOOKMARKS, root_node, "testtag"); | 373 wnode.InitUniqueByCreation(BOOKMARKS, root_node, "testtag"); |
| 374 EXPECT_EQ(syncer::WriteNode::INIT_SUCCESS, result); | 374 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 375 wnode.SetIsFolder(false); | 375 wnode.SetIsFolder(false); |
| 376 wnode.SetTitle(UTF8ToWide(test_title)); | 376 wnode.SetTitle(UTF8ToWide(test_title)); |
| 377 | 377 |
| 378 node_id = wnode.GetId(); | 378 node_id = wnode.GetId(); |
| 379 } | 379 } |
| 380 | 380 |
| 381 // Ensure we can delete something with a tag. | 381 // Ensure we can delete something with a tag. |
| 382 { | 382 { |
| 383 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 383 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 384 WriteNode wnode(&trans); | 384 WriteNode wnode(&trans); |
| 385 EXPECT_EQ(BaseNode::INIT_OK, | 385 EXPECT_EQ(BaseNode::INIT_OK, |
| 386 wnode.InitByClientTagLookup(syncer::BOOKMARKS, | 386 wnode.InitByClientTagLookup(BOOKMARKS, |
| 387 "testtag")); | 387 "testtag")); |
| 388 EXPECT_FALSE(wnode.GetIsFolder()); | 388 EXPECT_FALSE(wnode.GetIsFolder()); |
| 389 EXPECT_EQ(wnode.GetTitle(), test_title); | 389 EXPECT_EQ(wnode.GetTitle(), test_title); |
| 390 | 390 |
| 391 wnode.Remove(); | 391 wnode.Remove(); |
| 392 } | 392 } |
| 393 | 393 |
| 394 // Lookup of a node which was deleted should return failure, | 394 // Lookup of a node which was deleted should return failure, |
| 395 // but have found some data about the node. | 395 // but have found some data about the node. |
| 396 { | 396 { |
| 397 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 397 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 398 ReadNode node(&trans); | 398 ReadNode node(&trans); |
| 399 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL, | 399 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL, |
| 400 node.InitByClientTagLookup(syncer::BOOKMARKS, | 400 node.InitByClientTagLookup(BOOKMARKS, |
| 401 "testtag")); | 401 "testtag")); |
| 402 // Note that for proper function of this API this doesn't need to be | 402 // Note that for proper function of this API this doesn't need to be |
| 403 // filled, we're checking just to make sure the DB worked in this test. | 403 // filled, we're checking just to make sure the DB worked in this test. |
| 404 EXPECT_EQ(node.GetTitle(), test_title); | 404 EXPECT_EQ(node.GetTitle(), test_title); |
| 405 } | 405 } |
| 406 | 406 |
| 407 { | 407 { |
| 408 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 408 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 409 ReadNode folder_node(&trans); | 409 ReadNode folder_node(&trans); |
| 410 EXPECT_EQ(BaseNode::INIT_OK, folder_node.InitByIdLookup(folder_id)); | 410 EXPECT_EQ(BaseNode::INIT_OK, folder_node.InitByIdLookup(folder_id)); |
| 411 | 411 |
| 412 WriteNode wnode(&trans); | 412 WriteNode wnode(&trans); |
| 413 // This will undelete the tag. | 413 // This will undelete the tag. |
| 414 syncer::WriteNode::InitUniqueByCreationResult result = | 414 WriteNode::InitUniqueByCreationResult result = |
| 415 wnode.InitUniqueByCreation(syncer::BOOKMARKS, folder_node, "testtag"); | 415 wnode.InitUniqueByCreation(BOOKMARKS, folder_node, "testtag"); |
| 416 EXPECT_EQ(syncer::WriteNode::INIT_SUCCESS, result); | 416 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 417 EXPECT_EQ(wnode.GetIsFolder(), false); | 417 EXPECT_EQ(wnode.GetIsFolder(), false); |
| 418 EXPECT_EQ(wnode.GetParentId(), folder_node.GetId()); | 418 EXPECT_EQ(wnode.GetParentId(), folder_node.GetId()); |
| 419 EXPECT_EQ(wnode.GetId(), node_id); | 419 EXPECT_EQ(wnode.GetId(), node_id); |
| 420 EXPECT_NE(wnode.GetTitle(), test_title); // Title should be cleared | 420 EXPECT_NE(wnode.GetTitle(), test_title); // Title should be cleared |
| 421 wnode.SetTitle(UTF8ToWide(test_title)); | 421 wnode.SetTitle(UTF8ToWide(test_title)); |
| 422 } | 422 } |
| 423 | 423 |
| 424 // Now look up should work. | 424 // Now look up should work. |
| 425 { | 425 { |
| 426 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 426 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 427 ReadNode node(&trans); | 427 ReadNode node(&trans); |
| 428 EXPECT_EQ(BaseNode::INIT_OK, | 428 EXPECT_EQ(BaseNode::INIT_OK, |
| 429 node.InitByClientTagLookup(syncer::BOOKMARKS, | 429 node.InitByClientTagLookup(BOOKMARKS, |
| 430 "testtag")); | 430 "testtag")); |
| 431 EXPECT_EQ(node.GetTitle(), test_title); | 431 EXPECT_EQ(node.GetTitle(), test_title); |
| 432 EXPECT_EQ(node.GetModelType(), syncer::BOOKMARKS); | 432 EXPECT_EQ(node.GetModelType(), BOOKMARKS); |
| 433 } | 433 } |
| 434 } | 434 } |
| 435 | 435 |
| 436 TEST_F(SyncApiTest, WriteAndReadPassword) { | 436 TEST_F(SyncApiTest, WriteAndReadPassword) { |
| 437 KeyParams params = {"localhost", "username", "passphrase"}; | 437 KeyParams params = {"localhost", "username", "passphrase"}; |
| 438 { | 438 { |
| 439 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 439 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 440 trans.GetCryptographer()->AddKey(params); | 440 trans.GetCryptographer()->AddKey(params); |
| 441 } | 441 } |
| 442 { | 442 { |
| 443 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 443 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 444 ReadNode root_node(&trans); | 444 ReadNode root_node(&trans); |
| 445 root_node.InitByRootLookup(); | 445 root_node.InitByRootLookup(); |
| 446 | 446 |
| 447 WriteNode password_node(&trans); | 447 WriteNode password_node(&trans); |
| 448 syncer::WriteNode::InitUniqueByCreationResult result = | 448 WriteNode::InitUniqueByCreationResult result = |
| 449 password_node.InitUniqueByCreation(syncer::PASSWORDS, | 449 password_node.InitUniqueByCreation(PASSWORDS, |
| 450 root_node, "foo"); | 450 root_node, "foo"); |
| 451 EXPECT_EQ(syncer::WriteNode::INIT_SUCCESS, result); | 451 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 452 sync_pb::PasswordSpecificsData data; | 452 sync_pb::PasswordSpecificsData data; |
| 453 data.set_password_value("secret"); | 453 data.set_password_value("secret"); |
| 454 password_node.SetPasswordSpecifics(data); | 454 password_node.SetPasswordSpecifics(data); |
| 455 } | 455 } |
| 456 { | 456 { |
| 457 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 457 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 458 ReadNode root_node(&trans); | 458 ReadNode root_node(&trans); |
| 459 root_node.InitByRootLookup(); | 459 root_node.InitByRootLookup(); |
| 460 | 460 |
| 461 ReadNode password_node(&trans); | 461 ReadNode password_node(&trans); |
| 462 EXPECT_EQ(BaseNode::INIT_OK, | 462 EXPECT_EQ(BaseNode::INIT_OK, |
| 463 password_node.InitByClientTagLookup(syncer::PASSWORDS, | 463 password_node.InitByClientTagLookup(PASSWORDS, "foo")); |
| 464 "foo")); | |
| 465 const sync_pb::PasswordSpecificsData& data = | 464 const sync_pb::PasswordSpecificsData& data = |
| 466 password_node.GetPasswordSpecifics(); | 465 password_node.GetPasswordSpecifics(); |
| 467 EXPECT_EQ("secret", data.password_value()); | 466 EXPECT_EQ("secret", data.password_value()); |
| 468 } | 467 } |
| 469 } | 468 } |
| 470 | 469 |
| 471 TEST_F(SyncApiTest, WriteEncryptedTitle) { | 470 TEST_F(SyncApiTest, WriteEncryptedTitle) { |
| 472 KeyParams params = {"localhost", "username", "passphrase"}; | 471 KeyParams params = {"localhost", "username", "passphrase"}; |
| 473 { | 472 { |
| 474 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 473 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 475 trans.GetCryptographer()->AddKey(params); | 474 trans.GetCryptographer()->AddKey(params); |
| 476 trans.GetCryptographer()->set_encrypt_everything(); | 475 trans.GetCryptographer()->set_encrypt_everything(); |
| 477 } | 476 } |
| 478 { | 477 { |
| 479 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 478 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 480 ReadNode root_node(&trans); | 479 ReadNode root_node(&trans); |
| 481 root_node.InitByRootLookup(); | 480 root_node.InitByRootLookup(); |
| 482 | 481 |
| 483 WriteNode bookmark_node(&trans); | 482 WriteNode bookmark_node(&trans); |
| 484 syncer::WriteNode::InitUniqueByCreationResult result = | 483 WriteNode::InitUniqueByCreationResult result = |
| 485 bookmark_node.InitUniqueByCreation(syncer::BOOKMARKS, | 484 bookmark_node.InitUniqueByCreation(BOOKMARKS, |
| 486 root_node, "foo"); | 485 root_node, "foo"); |
| 487 EXPECT_EQ(syncer::WriteNode::INIT_SUCCESS, result); | 486 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 488 bookmark_node.SetTitle(UTF8ToWide("foo")); | 487 bookmark_node.SetTitle(UTF8ToWide("foo")); |
| 489 | 488 |
| 490 WriteNode pref_node(&trans); | 489 WriteNode pref_node(&trans); |
| 491 result = | 490 result = |
| 492 pref_node.InitUniqueByCreation(syncer::PREFERENCES, root_node, "bar"); | 491 pref_node.InitUniqueByCreation(PREFERENCES, root_node, "bar"); |
| 493 EXPECT_EQ(syncer::WriteNode::INIT_SUCCESS, result); | 492 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 494 pref_node.SetTitle(UTF8ToWide("bar")); | 493 pref_node.SetTitle(UTF8ToWide("bar")); |
| 495 } | 494 } |
| 496 { | 495 { |
| 497 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 496 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 498 ReadNode root_node(&trans); | 497 ReadNode root_node(&trans); |
| 499 root_node.InitByRootLookup(); | 498 root_node.InitByRootLookup(); |
| 500 | 499 |
| 501 ReadNode bookmark_node(&trans); | 500 ReadNode bookmark_node(&trans); |
| 502 EXPECT_EQ(BaseNode::INIT_OK, | 501 EXPECT_EQ(BaseNode::INIT_OK, |
| 503 bookmark_node.InitByClientTagLookup(syncer::BOOKMARKS, | 502 bookmark_node.InitByClientTagLookup(BOOKMARKS, |
| 504 "foo")); | 503 "foo")); |
| 505 EXPECT_EQ("foo", bookmark_node.GetTitle()); | 504 EXPECT_EQ("foo", bookmark_node.GetTitle()); |
| 506 EXPECT_EQ(kEncryptedString, | 505 EXPECT_EQ(kEncryptedString, |
| 507 bookmark_node.GetEntry()->Get(syncable::NON_UNIQUE_NAME)); | 506 bookmark_node.GetEntry()->Get(syncable::NON_UNIQUE_NAME)); |
| 508 | 507 |
| 509 ReadNode pref_node(&trans); | 508 ReadNode pref_node(&trans); |
| 510 EXPECT_EQ(BaseNode::INIT_OK, | 509 EXPECT_EQ(BaseNode::INIT_OK, |
| 511 pref_node.InitByClientTagLookup(syncer::PREFERENCES, | 510 pref_node.InitByClientTagLookup(PREFERENCES, |
| 512 "bar")); | 511 "bar")); |
| 513 EXPECT_EQ(kEncryptedString, pref_node.GetTitle()); | 512 EXPECT_EQ(kEncryptedString, pref_node.GetTitle()); |
| 514 } | 513 } |
| 515 } | 514 } |
| 516 | 515 |
| 517 TEST_F(SyncApiTest, BaseNodeSetSpecifics) { | 516 TEST_F(SyncApiTest, BaseNodeSetSpecifics) { |
| 518 int64 child_id = MakeNode(test_user_share_.user_share(), | 517 int64 child_id = MakeNode(test_user_share_.user_share(), |
| 519 syncer::BOOKMARKS, "testtag"); | 518 BOOKMARKS, "testtag"); |
| 520 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 519 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 521 WriteNode node(&trans); | 520 WriteNode node(&trans); |
| 522 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); | 521 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); |
| 523 | 522 |
| 524 sync_pb::EntitySpecifics entity_specifics; | 523 sync_pb::EntitySpecifics entity_specifics; |
| 525 entity_specifics.mutable_bookmark()->set_url("http://www.google.com"); | 524 entity_specifics.mutable_bookmark()->set_url("http://www.google.com"); |
| 526 | 525 |
| 527 EXPECT_NE(entity_specifics.SerializeAsString(), | 526 EXPECT_NE(entity_specifics.SerializeAsString(), |
| 528 node.GetEntitySpecifics().SerializeAsString()); | 527 node.GetEntitySpecifics().SerializeAsString()); |
| 529 node.SetEntitySpecifics(entity_specifics); | 528 node.SetEntitySpecifics(entity_specifics); |
| 530 EXPECT_EQ(entity_specifics.SerializeAsString(), | 529 EXPECT_EQ(entity_specifics.SerializeAsString(), |
| 531 node.GetEntitySpecifics().SerializeAsString()); | 530 node.GetEntitySpecifics().SerializeAsString()); |
| 532 } | 531 } |
| 533 | 532 |
| 534 TEST_F(SyncApiTest, BaseNodeSetSpecificsPreservesUnknownFields) { | 533 TEST_F(SyncApiTest, BaseNodeSetSpecificsPreservesUnknownFields) { |
| 535 int64 child_id = MakeNode(test_user_share_.user_share(), | 534 int64 child_id = MakeNode(test_user_share_.user_share(), |
| 536 syncer::BOOKMARKS, "testtag"); | 535 BOOKMARKS, "testtag"); |
| 537 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 536 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 538 WriteNode node(&trans); | 537 WriteNode node(&trans); |
| 539 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); | 538 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); |
| 540 EXPECT_TRUE(node.GetEntitySpecifics().unknown_fields().empty()); | 539 EXPECT_TRUE(node.GetEntitySpecifics().unknown_fields().empty()); |
| 541 | 540 |
| 542 sync_pb::EntitySpecifics entity_specifics; | 541 sync_pb::EntitySpecifics entity_specifics; |
| 543 entity_specifics.mutable_bookmark()->set_url("http://www.google.com"); | 542 entity_specifics.mutable_bookmark()->set_url("http://www.google.com"); |
| 544 entity_specifics.mutable_unknown_fields()->AddFixed32(5, 100); | 543 entity_specifics.mutable_unknown_fields()->AddFixed32(5, 100); |
| 545 node.SetEntitySpecifics(entity_specifics); | 544 node.SetEntitySpecifics(entity_specifics); |
| 546 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); | 545 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 558 { | 557 { |
| 559 bool is_folder = false; | 558 bool is_folder = false; |
| 560 EXPECT_TRUE(value.GetBoolean("isFolder", &is_folder)); | 559 EXPECT_TRUE(value.GetBoolean("isFolder", &is_folder)); |
| 561 EXPECT_EQ(node.GetIsFolder(), is_folder); | 560 EXPECT_EQ(node.GetIsFolder(), is_folder); |
| 562 } | 561 } |
| 563 ExpectDictStringValue(node.GetTitle(), value, "title"); | 562 ExpectDictStringValue(node.GetTitle(), value, "title"); |
| 564 { | 563 { |
| 565 ModelType expected_model_type = node.GetModelType(); | 564 ModelType expected_model_type = node.GetModelType(); |
| 566 std::string type_str; | 565 std::string type_str; |
| 567 EXPECT_TRUE(value.GetString("type", &type_str)); | 566 EXPECT_TRUE(value.GetString("type", &type_str)); |
| 568 if (expected_model_type >= syncer::FIRST_REAL_MODEL_TYPE) { | 567 if (expected_model_type >= FIRST_REAL_MODEL_TYPE) { |
| 569 ModelType model_type = syncer::ModelTypeFromString(type_str); | 568 ModelType model_type = ModelTypeFromString(type_str); |
| 570 EXPECT_EQ(expected_model_type, model_type); | 569 EXPECT_EQ(expected_model_type, model_type); |
| 571 } else if (expected_model_type == syncer::TOP_LEVEL_FOLDER) { | 570 } else if (expected_model_type == TOP_LEVEL_FOLDER) { |
| 572 EXPECT_EQ("Top-level folder", type_str); | 571 EXPECT_EQ("Top-level folder", type_str); |
| 573 } else if (expected_model_type == syncer::UNSPECIFIED) { | 572 } else if (expected_model_type == UNSPECIFIED) { |
| 574 EXPECT_EQ("Unspecified", type_str); | 573 EXPECT_EQ("Unspecified", type_str); |
| 575 } else { | 574 } else { |
| 576 ADD_FAILURE(); | 575 ADD_FAILURE(); |
| 577 } | 576 } |
| 578 } | 577 } |
| 579 if (is_detailed) { | 578 if (is_detailed) { |
| 580 ExpectInt64Value(node.GetParentId(), value, "parentId"); | 579 ExpectInt64Value(node.GetParentId(), value, "parentId"); |
| 581 ExpectTimeValue(node.GetModificationTime(), value, "modificationTime"); | 580 ExpectTimeValue(node.GetModificationTime(), value, "modificationTime"); |
| 582 ExpectInt64Value(node.GetExternalId(), value, "externalId"); | 581 ExpectInt64Value(node.GetExternalId(), value, "externalId"); |
| 583 ExpectInt64Value(node.GetPredecessorId(), value, "predecessorId"); | 582 ExpectInt64Value(node.GetPredecessorId(), value, "predecessorId"); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 ADD_FAILURE(); | 619 ADD_FAILURE(); |
| 621 } | 620 } |
| 622 } | 621 } |
| 623 | 622 |
| 624 TEST_F(SyncApiTest, EmptyTags) { | 623 TEST_F(SyncApiTest, EmptyTags) { |
| 625 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 624 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 626 ReadNode root_node(&trans); | 625 ReadNode root_node(&trans); |
| 627 root_node.InitByRootLookup(); | 626 root_node.InitByRootLookup(); |
| 628 WriteNode node(&trans); | 627 WriteNode node(&trans); |
| 629 std::string empty_tag; | 628 std::string empty_tag; |
| 630 syncer::WriteNode::InitUniqueByCreationResult result = | 629 WriteNode::InitUniqueByCreationResult result = |
| 631 node.InitUniqueByCreation(syncer::TYPED_URLS, root_node, empty_tag); | 630 node.InitUniqueByCreation(TYPED_URLS, root_node, empty_tag); |
| 632 EXPECT_NE(syncer::WriteNode::INIT_SUCCESS, result); | 631 EXPECT_NE(WriteNode::INIT_SUCCESS, result); |
| 633 EXPECT_EQ(BaseNode::INIT_FAILED_PRECONDITION, | 632 EXPECT_EQ(BaseNode::INIT_FAILED_PRECONDITION, |
| 634 node.InitByTagLookup(empty_tag)); | 633 node.InitByTagLookup(empty_tag)); |
| 635 } | 634 } |
| 636 | 635 |
| 637 namespace { | 636 namespace { |
| 638 | 637 |
| 639 class TestHttpPostProviderInterface : public HttpPostProviderInterface { | 638 class TestHttpPostProviderInterface : public HttpPostProviderInterface { |
| 640 public: | 639 public: |
| 641 virtual ~TestHttpPostProviderInterface() {} | 640 virtual ~TestHttpPostProviderInterface() {} |
| 642 | 641 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 }; | 673 }; |
| 675 | 674 |
| 676 class SyncManagerObserverMock : public SyncManager::Observer { | 675 class SyncManagerObserverMock : public SyncManager::Observer { |
| 677 public: | 676 public: |
| 678 MOCK_METHOD1(OnSyncCycleCompleted, | 677 MOCK_METHOD1(OnSyncCycleCompleted, |
| 679 void(const SyncSessionSnapshot&)); // NOLINT | 678 void(const SyncSessionSnapshot&)); // NOLINT |
| 680 MOCK_METHOD2(OnInitializationComplete, | 679 MOCK_METHOD2(OnInitializationComplete, |
| 681 void(const WeakHandle<JsBackend>&, bool)); // NOLINT | 680 void(const WeakHandle<JsBackend>&, bool)); // NOLINT |
| 682 MOCK_METHOD1(OnConnectionStatusChange, void(ConnectionStatus)); // NOLINT | 681 MOCK_METHOD1(OnConnectionStatusChange, void(ConnectionStatus)); // NOLINT |
| 683 MOCK_METHOD2(OnPassphraseRequired, | 682 MOCK_METHOD2(OnPassphraseRequired, |
| 684 void(syncer::PassphraseRequiredReason, | 683 void(PassphraseRequiredReason, |
| 685 const sync_pb::EncryptedData&)); // NOLINT | 684 const sync_pb::EncryptedData&)); // NOLINT |
| 686 MOCK_METHOD0(OnPassphraseAccepted, void()); // NOLINT | 685 MOCK_METHOD0(OnPassphraseAccepted, void()); // NOLINT |
| 687 MOCK_METHOD1(OnBootstrapTokenUpdated, void(const std::string&)); // NOLINT | 686 MOCK_METHOD1(OnBootstrapTokenUpdated, void(const std::string&)); // NOLINT |
| 688 MOCK_METHOD0(OnStopSyncingPermanently, void()); // NOLINT | 687 MOCK_METHOD0(OnStopSyncingPermanently, void()); // NOLINT |
| 689 MOCK_METHOD1(OnUpdatedToken, void(const std::string&)); // NOLINT | 688 MOCK_METHOD1(OnUpdatedToken, void(const std::string&)); // NOLINT |
| 690 MOCK_METHOD2(OnEncryptedTypesChanged, | 689 MOCK_METHOD2(OnEncryptedTypesChanged, |
| 691 void(ModelTypeSet, bool)); // NOLINT | 690 void(ModelTypeSet, bool)); // NOLINT |
| 692 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT | 691 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT |
| 693 MOCK_METHOD1(OnActionableError, | 692 MOCK_METHOD1(OnActionableError, |
| 694 void(const syncer::SyncProtocolError&)); // NOLINT | 693 void(const SyncProtocolError&)); // NOLINT |
| 695 }; | 694 }; |
| 696 | 695 |
| 697 class SyncNotifierMock : public syncer::SyncNotifier { | 696 class SyncNotifierMock : public SyncNotifier { |
| 698 public: | 697 public: |
| 699 MOCK_METHOD1(AddObserver, void(syncer::SyncNotifierObserver*)); | 698 MOCK_METHOD1(AddObserver, void(SyncNotifierObserver*)); |
| 700 MOCK_METHOD1(RemoveObserver, void(syncer::SyncNotifierObserver*)); | 699 MOCK_METHOD1(RemoveObserver, void(SyncNotifierObserver*)); |
| 701 MOCK_METHOD1(SetUniqueId, void(const std::string&)); | 700 MOCK_METHOD1(SetUniqueId, void(const std::string&)); |
| 702 MOCK_METHOD1(SetStateDeprecated, void(const std::string&)); | 701 MOCK_METHOD1(SetStateDeprecated, void(const std::string&)); |
| 703 MOCK_METHOD2(UpdateCredentials, | 702 MOCK_METHOD2(UpdateCredentials, |
| 704 void(const std::string&, const std::string&)); | 703 void(const std::string&, const std::string&)); |
| 705 MOCK_METHOD1(UpdateEnabledTypes, | 704 MOCK_METHOD1(UpdateEnabledTypes, |
| 706 void(syncer::ModelTypeSet)); | 705 void(ModelTypeSet)); |
| 707 MOCK_METHOD1(SendNotification, void(syncer::ModelTypeSet)); | 706 MOCK_METHOD1(SendNotification, void(ModelTypeSet)); |
| 708 }; | 707 }; |
| 709 | 708 |
| 710 } // namespace | 709 } // namespace |
| 711 | 710 |
| 712 class SyncManagerTest : public testing::Test, | 711 class SyncManagerTest : public testing::Test, |
| 713 public SyncManager::ChangeDelegate { | 712 public SyncManager::ChangeDelegate { |
| 714 protected: | 713 protected: |
| 715 enum NigoriStatus { | 714 enum NigoriStatus { |
| 716 DONT_WRITE_NIGORI, | 715 DONT_WRITE_NIGORI, |
| 717 WRITE_TO_NIGORI | 716 WRITE_TO_NIGORI |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 | 796 |
| 798 void TearDown() { | 797 void TearDown() { |
| 799 sync_manager_.RemoveObserver(&observer_); | 798 sync_manager_.RemoveObserver(&observer_); |
| 800 sync_manager_.ShutdownOnSyncThread(); | 799 sync_manager_.ShutdownOnSyncThread(); |
| 801 sync_notifier_mock_ = NULL; | 800 sync_notifier_mock_ = NULL; |
| 802 EXPECT_FALSE(sync_notifier_observer_); | 801 EXPECT_FALSE(sync_notifier_observer_); |
| 803 PumpLoop(); | 802 PumpLoop(); |
| 804 } | 803 } |
| 805 | 804 |
| 806 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { | 805 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) { |
| 807 (*out)[syncer::NIGORI] = syncer::GROUP_PASSIVE; | 806 (*out)[NIGORI] = GROUP_PASSIVE; |
| 808 (*out)[syncer::BOOKMARKS] = syncer::GROUP_PASSIVE; | 807 (*out)[BOOKMARKS] = GROUP_PASSIVE; |
| 809 (*out)[syncer::THEMES] = syncer::GROUP_PASSIVE; | 808 (*out)[THEMES] = GROUP_PASSIVE; |
| 810 (*out)[syncer::SESSIONS] = syncer::GROUP_PASSIVE; | 809 (*out)[SESSIONS] = GROUP_PASSIVE; |
| 811 (*out)[syncer::PASSWORDS] = syncer::GROUP_PASSIVE; | 810 (*out)[PASSWORDS] = GROUP_PASSIVE; |
| 812 (*out)[syncer::PREFERENCES] = syncer::GROUP_PASSIVE; | 811 (*out)[PREFERENCES] = GROUP_PASSIVE; |
| 813 } | 812 } |
| 814 | 813 |
| 815 virtual void OnChangesApplied( | 814 virtual void OnChangesApplied( |
| 816 syncer::ModelType model_type, | 815 ModelType model_type, |
| 817 const BaseTransaction* trans, | 816 const BaseTransaction* trans, |
| 818 const ImmutableChangeRecordList& changes) OVERRIDE {} | 817 const ImmutableChangeRecordList& changes) OVERRIDE {} |
| 819 | 818 |
| 820 virtual void OnChangesComplete(syncer::ModelType model_type) OVERRIDE {} | 819 virtual void OnChangesComplete(ModelType model_type) OVERRIDE {} |
| 821 | 820 |
| 822 // Helper methods. | 821 // Helper methods. |
| 823 bool SetUpEncryption(NigoriStatus nigori_status, | 822 bool SetUpEncryption(NigoriStatus nigori_status, |
| 824 EncryptionStatus encryption_status) { | 823 EncryptionStatus encryption_status) { |
| 825 UserShare* share = sync_manager_.GetUserShare(); | 824 UserShare* share = sync_manager_.GetUserShare(); |
| 826 share->directory->set_initial_sync_ended_for_type(syncer::NIGORI, true); | 825 share->directory->set_initial_sync_ended_for_type(NIGORI, true); |
| 827 | 826 |
| 828 // We need to create the nigori node as if it were an applied server update. | 827 // We need to create the nigori node as if it were an applied server update. |
| 829 int64 nigori_id = GetIdForDataType(syncer::NIGORI); | 828 int64 nigori_id = GetIdForDataType(NIGORI); |
| 830 if (nigori_id == kInvalidId) | 829 if (nigori_id == kInvalidId) |
| 831 return false; | 830 return false; |
| 832 | 831 |
| 833 // Set the nigori cryptographer information. | 832 // Set the nigori cryptographer information. |
| 834 WriteTransaction trans(FROM_HERE, share); | 833 WriteTransaction trans(FROM_HERE, share); |
| 835 Cryptographer* cryptographer = trans.GetCryptographer(); | 834 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 836 if (!cryptographer) | 835 if (!cryptographer) |
| 837 return false; | 836 return false; |
| 838 if (encryption_status != UNINITIALIZED) { | 837 if (encryption_status != UNINITIALIZED) { |
| 839 KeyParams params = {"localhost", "dummy", "foobar"}; | 838 KeyParams params = {"localhost", "dummy", "foobar"}; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 854 return cryptographer->is_ready(); | 853 return cryptographer->is_ready(); |
| 855 } | 854 } |
| 856 | 855 |
| 857 int64 GetIdForDataType(ModelType type) { | 856 int64 GetIdForDataType(ModelType type) { |
| 858 if (type_roots_.count(type) == 0) | 857 if (type_roots_.count(type) == 0) |
| 859 return 0; | 858 return 0; |
| 860 return type_roots_[type]; | 859 return type_roots_[type]; |
| 861 } | 860 } |
| 862 | 861 |
| 863 void SyncNotifierAddObserver( | 862 void SyncNotifierAddObserver( |
| 864 syncer::SyncNotifierObserver* sync_notifier_observer) { | 863 SyncNotifierObserver* sync_notifier_observer) { |
| 865 EXPECT_EQ(NULL, sync_notifier_observer_); | 864 EXPECT_EQ(NULL, sync_notifier_observer_); |
| 866 sync_notifier_observer_ = sync_notifier_observer; | 865 sync_notifier_observer_ = sync_notifier_observer; |
| 867 } | 866 } |
| 868 | 867 |
| 869 void SyncNotifierRemoveObserver( | 868 void SyncNotifierRemoveObserver( |
| 870 syncer::SyncNotifierObserver* sync_notifier_observer) { | 869 SyncNotifierObserver* sync_notifier_observer) { |
| 871 EXPECT_EQ(sync_notifier_observer_, sync_notifier_observer); | 870 EXPECT_EQ(sync_notifier_observer_, sync_notifier_observer); |
| 872 sync_notifier_observer_ = NULL; | 871 sync_notifier_observer_ = NULL; |
| 873 } | 872 } |
| 874 | 873 |
| 875 void SyncNotifierUpdateEnabledTypes(syncer::ModelTypeSet types) { | 874 void SyncNotifierUpdateEnabledTypes(ModelTypeSet types) { |
| 876 ModelSafeRoutingInfo routes; | 875 ModelSafeRoutingInfo routes; |
| 877 GetModelSafeRoutingInfo(&routes); | 876 GetModelSafeRoutingInfo(&routes); |
| 878 const syncer::ModelTypeSet expected_types = GetRoutingInfoTypes(routes); | 877 const ModelTypeSet expected_types = GetRoutingInfoTypes(routes); |
| 879 EXPECT_TRUE(types.Equals(expected_types)); | 878 EXPECT_TRUE(types.Equals(expected_types)); |
| 880 ++update_enabled_types_call_count_; | 879 ++update_enabled_types_call_count_; |
| 881 } | 880 } |
| 882 | 881 |
| 883 void PumpLoop() { | 882 void PumpLoop() { |
| 884 message_loop_.RunAllPending(); | 883 message_loop_.RunAllPending(); |
| 885 } | 884 } |
| 886 | 885 |
| 887 void SendJsMessage(const std::string& name, const JsArgList& args, | 886 void SendJsMessage(const std::string& name, const JsArgList& args, |
| 888 const WeakHandle<JsReplyHandler>& reply_handler) { | 887 const WeakHandle<JsReplyHandler>& reply_handler) { |
| 889 js_backend_.Call(FROM_HERE, &JsBackend::ProcessJsMessage, | 888 js_backend_.Call(FROM_HERE, &JsBackend::ProcessJsMessage, |
| 890 name, args, reply_handler); | 889 name, args, reply_handler); |
| 891 PumpLoop(); | 890 PumpLoop(); |
| 892 } | 891 } |
| 893 | 892 |
| 894 void SetJsEventHandler(const WeakHandle<JsEventHandler>& event_handler) { | 893 void SetJsEventHandler(const WeakHandle<JsEventHandler>& event_handler) { |
| 895 js_backend_.Call(FROM_HERE, &JsBackend::SetJsEventHandler, | 894 js_backend_.Call(FROM_HERE, &JsBackend::SetJsEventHandler, |
| 896 event_handler); | 895 event_handler); |
| 897 PumpLoop(); | 896 PumpLoop(); |
| 898 } | 897 } |
| 899 | 898 |
| 900 // Looks up an entry by client tag and resets IS_UNSYNCED value to false. | 899 // Looks up an entry by client tag and resets IS_UNSYNCED value to false. |
| 901 // Returns true if entry was previously unsynced, false if IS_UNSYNCED was | 900 // Returns true if entry was previously unsynced, false if IS_UNSYNCED was |
| 902 // already false. | 901 // already false. |
| 903 bool ResetUnsyncedEntry(syncer::ModelType type, | 902 bool ResetUnsyncedEntry(ModelType type, |
| 904 const std::string& client_tag) { | 903 const std::string& client_tag) { |
| 905 UserShare* share = sync_manager_.GetUserShare(); | 904 UserShare* share = sync_manager_.GetUserShare(); |
| 906 syncable::WriteTransaction trans( | 905 syncable::WriteTransaction trans( |
| 907 FROM_HERE, syncable::UNITTEST, share->directory.get()); | 906 FROM_HERE, syncable::UNITTEST, share->directory.get()); |
| 908 const std::string hash = BaseNode::GenerateSyncableHash(type, client_tag); | 907 const std::string hash = BaseNode::GenerateSyncableHash(type, client_tag); |
| 909 syncable::MutableEntry entry(&trans, syncable::GET_BY_CLIENT_TAG, | 908 syncable::MutableEntry entry(&trans, syncable::GET_BY_CLIENT_TAG, |
| 910 hash); | 909 hash); |
| 911 EXPECT_TRUE(entry.good()); | 910 EXPECT_TRUE(entry.good()); |
| 912 if (!entry.Get(IS_UNSYNCED)) | 911 if (!entry.Get(IS_UNSYNCED)) |
| 913 return false; | 912 return false; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 929 std::map<ModelType, int64> type_roots_; | 928 std::map<ModelType, int64> type_roots_; |
| 930 FakeExtensionsActivityMonitor extensions_activity_monitor_; | 929 FakeExtensionsActivityMonitor extensions_activity_monitor_; |
| 931 StrictMock<SyncNotifierMock>* sync_notifier_mock_; | 930 StrictMock<SyncNotifierMock>* sync_notifier_mock_; |
| 932 | 931 |
| 933 protected: | 932 protected: |
| 934 FakeEncryptor encryptor_; | 933 FakeEncryptor encryptor_; |
| 935 TestUnrecoverableErrorHandler handler_; | 934 TestUnrecoverableErrorHandler handler_; |
| 936 SyncManagerImpl sync_manager_; | 935 SyncManagerImpl sync_manager_; |
| 937 WeakHandle<JsBackend> js_backend_; | 936 WeakHandle<JsBackend> js_backend_; |
| 938 StrictMock<SyncManagerObserverMock> observer_; | 937 StrictMock<SyncManagerObserverMock> observer_; |
| 939 syncer::SyncNotifierObserver* sync_notifier_observer_; | 938 SyncNotifierObserver* sync_notifier_observer_; |
| 940 int update_enabled_types_call_count_; | 939 int update_enabled_types_call_count_; |
| 941 }; | 940 }; |
| 942 | 941 |
| 943 TEST_F(SyncManagerTest, UpdateEnabledTypes) { | 942 TEST_F(SyncManagerTest, UpdateEnabledTypes) { |
| 944 EXPECT_EQ(0, update_enabled_types_call_count_); | 943 EXPECT_EQ(0, update_enabled_types_call_count_); |
| 945 | 944 |
| 946 ModelSafeRoutingInfo routes; | 945 ModelSafeRoutingInfo routes; |
| 947 GetModelSafeRoutingInfo(&routes); | 946 GetModelSafeRoutingInfo(&routes); |
| 948 const syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); | 947 const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); |
| 949 | 948 |
| 950 sync_manager_.UpdateEnabledTypes(enabled_types); | 949 sync_manager_.UpdateEnabledTypes(enabled_types); |
| 951 EXPECT_EQ(1, update_enabled_types_call_count_); | 950 EXPECT_EQ(1, update_enabled_types_call_count_); |
| 952 } | 951 } |
| 953 | 952 |
| 954 TEST_F(SyncManagerTest, ProcessJsMessage) { | 953 TEST_F(SyncManagerTest, ProcessJsMessage) { |
| 955 const JsArgList kNoArgs; | 954 const JsArgList kNoArgs; |
| 956 | 955 |
| 957 StrictMock<MockJsReplyHandler> reply_handler; | 956 StrictMock<MockJsReplyHandler> reply_handler; |
| 958 | 957 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 void RunGetNodesByIdTest(const char* message_name, bool is_detailed) { | 1019 void RunGetNodesByIdTest(const char* message_name, bool is_detailed) { |
| 1021 int64 root_id = kInvalidId; | 1020 int64 root_id = kInvalidId; |
| 1022 { | 1021 { |
| 1023 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1022 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1024 ReadNode root_node(&trans); | 1023 ReadNode root_node(&trans); |
| 1025 root_node.InitByRootLookup(); | 1024 root_node.InitByRootLookup(); |
| 1026 root_id = root_node.GetId(); | 1025 root_id = root_node.GetId(); |
| 1027 } | 1026 } |
| 1028 | 1027 |
| 1029 int64 child_id = | 1028 int64 child_id = |
| 1030 MakeNode(sync_manager_.GetUserShare(), syncer::BOOKMARKS, "testtag"); | 1029 MakeNode(sync_manager_.GetUserShare(), BOOKMARKS, "testtag"); |
| 1031 | 1030 |
| 1032 StrictMock<MockJsReplyHandler> reply_handler; | 1031 StrictMock<MockJsReplyHandler> reply_handler; |
| 1033 | 1032 |
| 1034 JsArgList return_args; | 1033 JsArgList return_args; |
| 1035 | 1034 |
| 1036 const int64 ids[] = { root_id, child_id }; | 1035 const int64 ids[] = { root_id, child_id }; |
| 1037 | 1036 |
| 1038 EXPECT_CALL(reply_handler, | 1037 EXPECT_CALL(reply_handler, |
| 1039 HandleJsReply(message_name, _)) | 1038 HandleJsReply(message_name, _)) |
| 1040 .Times(arraysize(ids)).WillRepeatedly(SaveArg<1>(&return_args)); | 1039 .Times(arraysize(ids)).WillRepeatedly(SaveArg<1>(&return_args)); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1251 | 1250 |
| 1252 EXPECT_CALL(event_handler, | 1251 EXPECT_CALL(event_handler, |
| 1253 HandleJsEvent("onNotificationStateChange", | 1252 HandleJsEvent("onNotificationStateChange", |
| 1254 HasDetailsAsDictionary(true_details))); | 1253 HasDetailsAsDictionary(true_details))); |
| 1255 EXPECT_CALL(event_handler, | 1254 EXPECT_CALL(event_handler, |
| 1256 HandleJsEvent("onNotificationStateChange", | 1255 HandleJsEvent("onNotificationStateChange", |
| 1257 HasDetailsAsDictionary(false_details))); | 1256 HasDetailsAsDictionary(false_details))); |
| 1258 | 1257 |
| 1259 sync_manager_.SimulateEnableNotificationsForTest(); | 1258 sync_manager_.SimulateEnableNotificationsForTest(); |
| 1260 sync_manager_.SimulateDisableNotificationsForTest( | 1259 sync_manager_.SimulateDisableNotificationsForTest( |
| 1261 syncer::TRANSIENT_NOTIFICATION_ERROR); | 1260 TRANSIENT_NOTIFICATION_ERROR); |
| 1262 | 1261 |
| 1263 SetJsEventHandler(event_handler.AsWeakHandle()); | 1262 SetJsEventHandler(event_handler.AsWeakHandle()); |
| 1264 sync_manager_.SimulateEnableNotificationsForTest(); | 1263 sync_manager_.SimulateEnableNotificationsForTest(); |
| 1265 sync_manager_.SimulateDisableNotificationsForTest( | 1264 sync_manager_.SimulateDisableNotificationsForTest( |
| 1266 syncer::TRANSIENT_NOTIFICATION_ERROR); | 1265 TRANSIENT_NOTIFICATION_ERROR); |
| 1267 SetJsEventHandler(WeakHandle<JsEventHandler>()); | 1266 SetJsEventHandler(WeakHandle<JsEventHandler>()); |
| 1268 | 1267 |
| 1269 sync_manager_.SimulateEnableNotificationsForTest(); | 1268 sync_manager_.SimulateEnableNotificationsForTest(); |
| 1270 sync_manager_.SimulateDisableNotificationsForTest( | 1269 sync_manager_.SimulateDisableNotificationsForTest( |
| 1271 syncer::TRANSIENT_NOTIFICATION_ERROR); | 1270 TRANSIENT_NOTIFICATION_ERROR); |
| 1272 | 1271 |
| 1273 // Should trigger the replies. | 1272 // Should trigger the replies. |
| 1274 PumpLoop(); | 1273 PumpLoop(); |
| 1275 } | 1274 } |
| 1276 | 1275 |
| 1277 TEST_F(SyncManagerTest, OnIncomingNotification) { | 1276 TEST_F(SyncManagerTest, OnIncomingNotification) { |
| 1278 StrictMock<MockJsEventHandler> event_handler; | 1277 StrictMock<MockJsEventHandler> event_handler; |
| 1279 | 1278 |
| 1280 const syncer::ModelTypeSet empty_model_types; | 1279 const ModelTypeSet empty_model_types; |
| 1281 const syncer::ModelTypeSet model_types( | 1280 const ModelTypeSet model_types( |
| 1282 syncer::BOOKMARKS, syncer::THEMES); | 1281 BOOKMARKS, THEMES); |
| 1283 | 1282 |
| 1284 // Build expected_args to have a single argument with the string | 1283 // Build expected_args to have a single argument with the string |
| 1285 // equivalents of model_types. | 1284 // equivalents of model_types. |
| 1286 DictionaryValue expected_details; | 1285 DictionaryValue expected_details; |
| 1287 { | 1286 { |
| 1288 ListValue* model_type_list = new ListValue(); | 1287 ListValue* model_type_list = new ListValue(); |
| 1289 expected_details.SetString("source", "REMOTE_NOTIFICATION"); | 1288 expected_details.SetString("source", "REMOTE_NOTIFICATION"); |
| 1290 expected_details.Set("changedTypes", model_type_list); | 1289 expected_details.Set("changedTypes", model_type_list); |
| 1291 for (syncer::ModelTypeSet::Iterator it = model_types.First(); | 1290 for (ModelTypeSet::Iterator it = model_types.First(); |
| 1292 it.Good(); it.Inc()) { | 1291 it.Good(); it.Inc()) { |
| 1293 model_type_list->Append( | 1292 model_type_list->Append( |
| 1294 Value::CreateStringValue(syncer::ModelTypeToString(it.Get()))); | 1293 Value::CreateStringValue(ModelTypeToString(it.Get()))); |
| 1295 } | 1294 } |
| 1296 } | 1295 } |
| 1297 | 1296 |
| 1298 EXPECT_CALL(event_handler, | 1297 EXPECT_CALL(event_handler, |
| 1299 HandleJsEvent("onIncomingNotification", | 1298 HandleJsEvent("onIncomingNotification", |
| 1300 HasDetailsAsDictionary(expected_details))); | 1299 HasDetailsAsDictionary(expected_details))); |
| 1301 | 1300 |
| 1302 sync_manager_.TriggerOnIncomingNotificationForTest(empty_model_types); | 1301 sync_manager_.TriggerOnIncomingNotificationForTest(empty_model_types); |
| 1303 sync_manager_.TriggerOnIncomingNotificationForTest(model_types); | 1302 sync_manager_.TriggerOnIncomingNotificationForTest(model_types); |
| 1304 | 1303 |
| 1305 SetJsEventHandler(event_handler.AsWeakHandle()); | 1304 SetJsEventHandler(event_handler.AsWeakHandle()); |
| 1306 sync_manager_.TriggerOnIncomingNotificationForTest(model_types); | 1305 sync_manager_.TriggerOnIncomingNotificationForTest(model_types); |
| 1307 SetJsEventHandler(WeakHandle<JsEventHandler>()); | 1306 SetJsEventHandler(WeakHandle<JsEventHandler>()); |
| 1308 | 1307 |
| 1309 sync_manager_.TriggerOnIncomingNotificationForTest(empty_model_types); | 1308 sync_manager_.TriggerOnIncomingNotificationForTest(empty_model_types); |
| 1310 sync_manager_.TriggerOnIncomingNotificationForTest(model_types); | 1309 sync_manager_.TriggerOnIncomingNotificationForTest(model_types); |
| 1311 | 1310 |
| 1312 // Should trigger the replies. | 1311 // Should trigger the replies. |
| 1313 PumpLoop(); | 1312 PumpLoop(); |
| 1314 } | 1313 } |
| 1315 | 1314 |
| 1316 TEST_F(SyncManagerTest, RefreshEncryptionReady) { | 1315 TEST_F(SyncManagerTest, RefreshEncryptionReady) { |
| 1317 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1316 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 1318 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1317 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 1319 | 1318 |
| 1320 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); | 1319 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); |
| 1321 PumpLoop(); | 1320 PumpLoop(); |
| 1322 | 1321 |
| 1323 const syncer::ModelTypeSet encrypted_types = | 1322 const ModelTypeSet encrypted_types = |
| 1324 sync_manager_.GetEncryptedDataTypesForTest(); | 1323 sync_manager_.GetEncryptedDataTypesForTest(); |
| 1325 EXPECT_TRUE(encrypted_types.Has(syncer::PASSWORDS)); | 1324 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); |
| 1326 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); | 1325 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); |
| 1327 { | 1326 { |
| 1328 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1327 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1329 ReadNode node(&trans); | 1328 ReadNode node(&trans); |
| 1330 EXPECT_EQ(BaseNode::INIT_OK, | 1329 EXPECT_EQ(BaseNode::INIT_OK, |
| 1331 node.InitByIdLookup(GetIdForDataType(syncer::NIGORI))); | 1330 node.InitByIdLookup(GetIdForDataType(NIGORI))); |
| 1332 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); | 1331 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); |
| 1333 EXPECT_TRUE(nigori.has_encrypted()); | 1332 EXPECT_TRUE(nigori.has_encrypted()); |
| 1334 Cryptographer* cryptographer = trans.GetCryptographer(); | 1333 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1335 EXPECT_TRUE(cryptographer->is_ready()); | 1334 EXPECT_TRUE(cryptographer->is_ready()); |
| 1336 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); | 1335 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); |
| 1337 } | 1336 } |
| 1338 } | 1337 } |
| 1339 | 1338 |
| 1340 // Attempt to refresh encryption when nigori not downloaded. | 1339 // Attempt to refresh encryption when nigori not downloaded. |
| 1341 TEST_F(SyncManagerTest, RefreshEncryptionNotReady) { | 1340 TEST_F(SyncManagerTest, RefreshEncryptionNotReady) { |
| 1342 // Don't set up encryption (no nigori node created). | 1341 // Don't set up encryption (no nigori node created). |
| 1343 | 1342 |
| 1344 // Should fail. | 1343 // Should fail. |
| 1345 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); | 1344 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); |
| 1346 PumpLoop(); | 1345 PumpLoop(); |
| 1347 | 1346 |
| 1348 const syncer::ModelTypeSet encrypted_types = | 1347 const ModelTypeSet encrypted_types = |
| 1349 sync_manager_.GetEncryptedDataTypesForTest(); | 1348 sync_manager_.GetEncryptedDataTypesForTest(); |
| 1350 EXPECT_TRUE(encrypted_types.Has(syncer::PASSWORDS)); // Hardcoded. | 1349 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); // Hardcoded. |
| 1351 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); | 1350 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); |
| 1352 } | 1351 } |
| 1353 | 1352 |
| 1354 // Attempt to refresh encryption when nigori is empty. | 1353 // Attempt to refresh encryption when nigori is empty. |
| 1355 TEST_F(SyncManagerTest, RefreshEncryptionEmptyNigori) { | 1354 TEST_F(SyncManagerTest, RefreshEncryptionEmptyNigori) { |
| 1356 EXPECT_TRUE(SetUpEncryption(DONT_WRITE_NIGORI, DEFAULT_ENCRYPTION)); | 1355 EXPECT_TRUE(SetUpEncryption(DONT_WRITE_NIGORI, DEFAULT_ENCRYPTION)); |
| 1357 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1356 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 1358 | 1357 |
| 1359 // Should write to nigori. | 1358 // Should write to nigori. |
| 1360 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); | 1359 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); |
| 1361 PumpLoop(); | 1360 PumpLoop(); |
| 1362 | 1361 |
| 1363 const syncer::ModelTypeSet encrypted_types = | 1362 const ModelTypeSet encrypted_types = |
| 1364 sync_manager_.GetEncryptedDataTypesForTest(); | 1363 sync_manager_.GetEncryptedDataTypesForTest(); |
| 1365 EXPECT_TRUE(encrypted_types.Has(syncer::PASSWORDS)); // Hardcoded. | 1364 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); // Hardcoded. |
| 1366 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); | 1365 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); |
| 1367 { | 1366 { |
| 1368 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1367 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1369 ReadNode node(&trans); | 1368 ReadNode node(&trans); |
| 1370 EXPECT_EQ(BaseNode::INIT_OK, | 1369 EXPECT_EQ(BaseNode::INIT_OK, |
| 1371 node.InitByIdLookup(GetIdForDataType(syncer::NIGORI))); | 1370 node.InitByIdLookup(GetIdForDataType(NIGORI))); |
| 1372 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); | 1371 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); |
| 1373 EXPECT_TRUE(nigori.has_encrypted()); | 1372 EXPECT_TRUE(nigori.has_encrypted()); |
| 1374 Cryptographer* cryptographer = trans.GetCryptographer(); | 1373 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1375 EXPECT_TRUE(cryptographer->is_ready()); | 1374 EXPECT_TRUE(cryptographer->is_ready()); |
| 1376 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); | 1375 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); |
| 1377 } | 1376 } |
| 1378 } | 1377 } |
| 1379 | 1378 |
| 1380 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) { | 1379 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) { |
| 1381 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1380 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 1382 EXPECT_CALL(observer_, | 1381 EXPECT_CALL(observer_, |
| 1383 OnEncryptedTypesChanged( | 1382 OnEncryptedTypesChanged( |
| 1384 HasModelTypes(syncer::ModelTypeSet::All()), true)); | 1383 HasModelTypes(ModelTypeSet::All()), true)); |
| 1385 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1384 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 1386 sync_manager_.EnableEncryptEverything(); | 1385 sync_manager_.EnableEncryptEverything(); |
| 1387 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabledForTest()); | 1386 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabledForTest()); |
| 1388 } | 1387 } |
| 1389 | 1388 |
| 1390 TEST_F(SyncManagerTest, EncryptDataTypesWithData) { | 1389 TEST_F(SyncManagerTest, EncryptDataTypesWithData) { |
| 1391 size_t batch_size = 5; | 1390 size_t batch_size = 5; |
| 1392 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1391 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 1393 | 1392 |
| 1394 // Create some unencrypted unsynced data. | 1393 // Create some unencrypted unsynced data. |
| 1395 int64 folder = MakeFolderWithParent(sync_manager_.GetUserShare(), | 1394 int64 folder = MakeFolderWithParent(sync_manager_.GetUserShare(), |
| 1396 syncer::BOOKMARKS, | 1395 BOOKMARKS, |
| 1397 GetIdForDataType(syncer::BOOKMARKS), | 1396 GetIdForDataType(BOOKMARKS), |
| 1398 NULL); | 1397 NULL); |
| 1399 // First batch_size nodes are children of folder. | 1398 // First batch_size nodes are children of folder. |
| 1400 size_t i; | 1399 size_t i; |
| 1401 for (i = 0; i < batch_size; ++i) { | 1400 for (i = 0; i < batch_size; ++i) { |
| 1402 MakeNodeWithParent(sync_manager_.GetUserShare(), syncer::BOOKMARKS, | 1401 MakeNodeWithParent(sync_manager_.GetUserShare(), BOOKMARKS, |
| 1403 base::StringPrintf("%"PRIuS"", i), folder); | 1402 base::StringPrintf("%"PRIuS"", i), folder); |
| 1404 } | 1403 } |
| 1405 // Next batch_size nodes are a different type and on their own. | 1404 // Next batch_size nodes are a different type and on their own. |
| 1406 for (; i < 2*batch_size; ++i) { | 1405 for (; i < 2*batch_size; ++i) { |
| 1407 MakeNodeWithParent(sync_manager_.GetUserShare(), syncer::SESSIONS, | 1406 MakeNodeWithParent(sync_manager_.GetUserShare(), SESSIONS, |
| 1408 base::StringPrintf("%"PRIuS"", i), | 1407 base::StringPrintf("%"PRIuS"", i), |
| 1409 GetIdForDataType(syncer::SESSIONS)); | 1408 GetIdForDataType(SESSIONS)); |
| 1410 } | 1409 } |
| 1411 // Last batch_size nodes are a third type that will not need encryption. | 1410 // Last batch_size nodes are a third type that will not need encryption. |
| 1412 for (; i < 3*batch_size; ++i) { | 1411 for (; i < 3*batch_size; ++i) { |
| 1413 MakeNodeWithParent(sync_manager_.GetUserShare(), syncer::THEMES, | 1412 MakeNodeWithParent(sync_manager_.GetUserShare(), THEMES, |
| 1414 base::StringPrintf("%"PRIuS"", i), | 1413 base::StringPrintf("%"PRIuS"", i), |
| 1415 GetIdForDataType(syncer::THEMES)); | 1414 GetIdForDataType(THEMES)); |
| 1416 } | 1415 } |
| 1417 | 1416 |
| 1418 { | 1417 { |
| 1419 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1418 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1420 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals( | 1419 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals( |
| 1421 Cryptographer::SensitiveTypes())); | 1420 Cryptographer::SensitiveTypes())); |
| 1422 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1421 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1423 trans.GetWrappedTrans(), | 1422 trans.GetWrappedTrans(), |
| 1424 trans.GetCryptographer(), | 1423 trans.GetCryptographer(), |
| 1425 syncer::BOOKMARKS, | 1424 BOOKMARKS, |
| 1426 false /* not encrypted */)); | 1425 false /* not encrypted */)); |
| 1427 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1426 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1428 trans.GetWrappedTrans(), | 1427 trans.GetWrappedTrans(), |
| 1429 trans.GetCryptographer(), | 1428 trans.GetCryptographer(), |
| 1430 syncer::SESSIONS, | 1429 SESSIONS, |
| 1431 false /* not encrypted */)); | 1430 false /* not encrypted */)); |
| 1432 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1431 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1433 trans.GetWrappedTrans(), | 1432 trans.GetWrappedTrans(), |
| 1434 trans.GetCryptographer(), | 1433 trans.GetCryptographer(), |
| 1435 syncer::THEMES, | 1434 THEMES, |
| 1436 false /* not encrypted */)); | 1435 false /* not encrypted */)); |
| 1437 } | 1436 } |
| 1438 | 1437 |
| 1439 EXPECT_CALL(observer_, | 1438 EXPECT_CALL(observer_, |
| 1440 OnEncryptedTypesChanged( | 1439 OnEncryptedTypesChanged( |
| 1441 HasModelTypes(syncer::ModelTypeSet::All()), true)); | 1440 HasModelTypes(ModelTypeSet::All()), true)); |
| 1442 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1441 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 1443 sync_manager_.EnableEncryptEverything(); | 1442 sync_manager_.EnableEncryptEverything(); |
| 1444 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabledForTest()); | 1443 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabledForTest()); |
| 1445 { | 1444 { |
| 1446 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1445 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1447 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals( | 1446 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals( |
| 1448 syncer::ModelTypeSet::All())); | 1447 ModelTypeSet::All())); |
| 1449 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1448 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1450 trans.GetWrappedTrans(), | 1449 trans.GetWrappedTrans(), |
| 1451 trans.GetCryptographer(), | 1450 trans.GetCryptographer(), |
| 1452 syncer::BOOKMARKS, | 1451 BOOKMARKS, |
| 1453 true /* is encrypted */)); | 1452 true /* is encrypted */)); |
| 1454 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1453 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1455 trans.GetWrappedTrans(), | 1454 trans.GetWrappedTrans(), |
| 1456 trans.GetCryptographer(), | 1455 trans.GetCryptographer(), |
| 1457 syncer::SESSIONS, | 1456 SESSIONS, |
| 1458 true /* is encrypted */)); | 1457 true /* is encrypted */)); |
| 1459 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1458 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1460 trans.GetWrappedTrans(), | 1459 trans.GetWrappedTrans(), |
| 1461 trans.GetCryptographer(), | 1460 trans.GetCryptographer(), |
| 1462 syncer::THEMES, | 1461 THEMES, |
| 1463 true /* is encrypted */)); | 1462 true /* is encrypted */)); |
| 1464 } | 1463 } |
| 1465 | 1464 |
| 1466 // Trigger's a ReEncryptEverything with new passphrase. | 1465 // Trigger's a ReEncryptEverything with new passphrase. |
| 1467 testing::Mock::VerifyAndClearExpectations(&observer_); | 1466 testing::Mock::VerifyAndClearExpectations(&observer_); |
| 1468 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); | 1467 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); |
| 1469 EXPECT_CALL(observer_, OnPassphraseAccepted()); | 1468 EXPECT_CALL(observer_, OnPassphraseAccepted()); |
| 1470 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1469 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 1471 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); | 1470 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); |
| 1472 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabledForTest()); | 1471 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabledForTest()); |
| 1473 { | 1472 { |
| 1474 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1473 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1475 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals(syncer::ModelTypeSet::All())); | 1474 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals(ModelTypeSet::All())); |
| 1476 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1475 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1477 trans.GetWrappedTrans(), | 1476 trans.GetWrappedTrans(), |
| 1478 trans.GetCryptographer(), | 1477 trans.GetCryptographer(), |
| 1479 syncer::BOOKMARKS, | 1478 BOOKMARKS, |
| 1480 true /* is encrypted */)); | 1479 true /* is encrypted */)); |
| 1481 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1480 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1482 trans.GetWrappedTrans(), | 1481 trans.GetWrappedTrans(), |
| 1483 trans.GetCryptographer(), | 1482 trans.GetCryptographer(), |
| 1484 syncer::SESSIONS, | 1483 SESSIONS, |
| 1485 true /* is encrypted */)); | 1484 true /* is encrypted */)); |
| 1486 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1485 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1487 trans.GetWrappedTrans(), | 1486 trans.GetWrappedTrans(), |
| 1488 trans.GetCryptographer(), | 1487 trans.GetCryptographer(), |
| 1489 syncer::THEMES, | 1488 THEMES, |
| 1490 true /* is encrypted */)); | 1489 true /* is encrypted */)); |
| 1491 } | 1490 } |
| 1492 // Calling EncryptDataTypes with an empty encrypted types should not trigger | 1491 // Calling EncryptDataTypes with an empty encrypted types should not trigger |
| 1493 // a reencryption and should just notify immediately. | 1492 // a reencryption and should just notify immediately. |
| 1494 // TODO(zea): add logic to ensure nothing was written. | 1493 // TODO(zea): add logic to ensure nothing was written. |
| 1495 testing::Mock::VerifyAndClearExpectations(&observer_); | 1494 testing::Mock::VerifyAndClearExpectations(&observer_); |
| 1496 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)).Times(0); | 1495 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)).Times(0); |
| 1497 EXPECT_CALL(observer_, OnPassphraseAccepted()).Times(0); | 1496 EXPECT_CALL(observer_, OnPassphraseAccepted()).Times(0); |
| 1498 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1497 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 1499 sync_manager_.EnableEncryptEverything(); | 1498 sync_manager_.EnableEncryptEverything(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1560 // Store the default (soon to be old) key. | 1559 // Store the default (soon to be old) key. |
| 1561 Cryptographer* cryptographer = trans.GetCryptographer(); | 1560 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1562 std::string bootstrap_token; | 1561 std::string bootstrap_token; |
| 1563 cryptographer->GetBootstrapToken(&bootstrap_token); | 1562 cryptographer->GetBootstrapToken(&bootstrap_token); |
| 1564 verifier.Bootstrap(bootstrap_token); | 1563 verifier.Bootstrap(bootstrap_token); |
| 1565 | 1564 |
| 1566 ReadNode root_node(&trans); | 1565 ReadNode root_node(&trans); |
| 1567 root_node.InitByRootLookup(); | 1566 root_node.InitByRootLookup(); |
| 1568 | 1567 |
| 1569 WriteNode password_node(&trans); | 1568 WriteNode password_node(&trans); |
| 1570 syncer::WriteNode::InitUniqueByCreationResult result = | 1569 WriteNode::InitUniqueByCreationResult result = |
| 1571 password_node.InitUniqueByCreation(syncer::PASSWORDS, | 1570 password_node.InitUniqueByCreation(PASSWORDS, |
| 1572 root_node, "foo"); | 1571 root_node, "foo"); |
| 1573 EXPECT_EQ(syncer::WriteNode::INIT_SUCCESS, result); | 1572 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 1574 sync_pb::PasswordSpecificsData data; | 1573 sync_pb::PasswordSpecificsData data; |
| 1575 data.set_password_value("secret"); | 1574 data.set_password_value("secret"); |
| 1576 password_node.SetPasswordSpecifics(data); | 1575 password_node.SetPasswordSpecifics(data); |
| 1577 } | 1576 } |
| 1578 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); | 1577 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); |
| 1579 EXPECT_CALL(observer_, OnPassphraseAccepted()); | 1578 EXPECT_CALL(observer_, OnPassphraseAccepted()); |
| 1580 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1579 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 1581 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); | 1580 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); |
| 1582 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); | 1581 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); |
| 1583 { | 1582 { |
| 1584 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1583 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1585 Cryptographer* cryptographer = trans.GetCryptographer(); | 1584 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1586 EXPECT_TRUE(cryptographer->is_ready()); | 1585 EXPECT_TRUE(cryptographer->is_ready()); |
| 1587 // Verify the default key has changed. | 1586 // Verify the default key has changed. |
| 1588 sync_pb::EncryptedData encrypted; | 1587 sync_pb::EncryptedData encrypted; |
| 1589 cryptographer->GetKeys(&encrypted); | 1588 cryptographer->GetKeys(&encrypted); |
| 1590 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); | 1589 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); |
| 1591 | 1590 |
| 1592 ReadNode password_node(&trans); | 1591 ReadNode password_node(&trans); |
| 1593 EXPECT_EQ(BaseNode::INIT_OK, | 1592 EXPECT_EQ(BaseNode::INIT_OK, |
| 1594 password_node.InitByClientTagLookup(syncer::PASSWORDS, | 1593 password_node.InitByClientTagLookup(PASSWORDS, |
| 1595 "foo")); | 1594 "foo")); |
| 1596 const sync_pb::PasswordSpecificsData& data = | 1595 const sync_pb::PasswordSpecificsData& data = |
| 1597 password_node.GetPasswordSpecifics(); | 1596 password_node.GetPasswordSpecifics(); |
| 1598 EXPECT_EQ("secret", data.password_value()); | 1597 EXPECT_EQ("secret", data.password_value()); |
| 1599 } | 1598 } |
| 1600 } | 1599 } |
| 1601 | 1600 |
| 1602 // Manually set the pending keys in the cryptographer/nigori to reflect the data | 1601 // Manually set the pending keys in the cryptographer/nigori to reflect the data |
| 1603 // being encrypted with a new (unprovided) GAIA password, then supply the | 1602 // being encrypted with a new (unprovided) GAIA password, then supply the |
| 1604 // password. | 1603 // password. |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1794 TEST_F(SyncManagerTest, SetPassphraseWithEmptyPasswordNode) { | 1793 TEST_F(SyncManagerTest, SetPassphraseWithEmptyPasswordNode) { |
| 1795 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1794 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 1796 int64 node_id = 0; | 1795 int64 node_id = 0; |
| 1797 std::string tag = "foo"; | 1796 std::string tag = "foo"; |
| 1798 { | 1797 { |
| 1799 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1798 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1800 ReadNode root_node(&trans); | 1799 ReadNode root_node(&trans); |
| 1801 root_node.InitByRootLookup(); | 1800 root_node.InitByRootLookup(); |
| 1802 | 1801 |
| 1803 WriteNode password_node(&trans); | 1802 WriteNode password_node(&trans); |
| 1804 syncer::WriteNode::InitUniqueByCreationResult result = | 1803 WriteNode::InitUniqueByCreationResult result = |
| 1805 password_node.InitUniqueByCreation(syncer::PASSWORDS, root_node, tag); | 1804 password_node.InitUniqueByCreation(PASSWORDS, root_node, tag); |
| 1806 EXPECT_EQ(syncer::WriteNode::INIT_SUCCESS, result); | 1805 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 1807 node_id = password_node.GetId(); | 1806 node_id = password_node.GetId(); |
| 1808 } | 1807 } |
| 1809 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); | 1808 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); |
| 1810 EXPECT_CALL(observer_, OnPassphraseAccepted()); | 1809 EXPECT_CALL(observer_, OnPassphraseAccepted()); |
| 1811 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1810 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 1812 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); | 1811 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); |
| 1813 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); | 1812 EXPECT_FALSE(sync_manager_.EncryptEverythingEnabledForTest()); |
| 1814 { | 1813 { |
| 1815 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1814 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1816 ReadNode password_node(&trans); | 1815 ReadNode password_node(&trans); |
| 1817 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY, | 1816 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY, |
| 1818 password_node.InitByClientTagLookup(syncer::PASSWORDS, | 1817 password_node.InitByClientTagLookup(PASSWORDS, |
| 1819 tag)); | 1818 tag)); |
| 1820 } | 1819 } |
| 1821 { | 1820 { |
| 1822 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1821 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1823 ReadNode password_node(&trans); | 1822 ReadNode password_node(&trans); |
| 1824 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY, | 1823 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY, |
| 1825 password_node.InitByIdLookup(node_id)); | 1824 password_node.InitByIdLookup(node_id)); |
| 1826 } | 1825 } |
| 1827 } | 1826 } |
| 1828 | 1827 |
| 1829 TEST_F(SyncManagerTest, NudgeDelayTest) { | 1828 TEST_F(SyncManagerTest, NudgeDelayTest) { |
| 1830 EXPECT_EQ(sync_manager_.GetNudgeDelayTimeDelta(syncer::BOOKMARKS), | 1829 EXPECT_EQ(sync_manager_.GetNudgeDelayTimeDelta(BOOKMARKS), |
| 1831 base::TimeDelta::FromMilliseconds( | 1830 base::TimeDelta::FromMilliseconds( |
| 1832 SyncManagerImpl::GetDefaultNudgeDelay())); | 1831 SyncManagerImpl::GetDefaultNudgeDelay())); |
| 1833 | 1832 |
| 1834 EXPECT_EQ(sync_manager_.GetNudgeDelayTimeDelta(syncer::AUTOFILL), | 1833 EXPECT_EQ(sync_manager_.GetNudgeDelayTimeDelta(AUTOFILL), |
| 1835 base::TimeDelta::FromSeconds( | 1834 base::TimeDelta::FromSeconds( |
| 1836 syncer::kDefaultShortPollIntervalSeconds)); | 1835 kDefaultShortPollIntervalSeconds)); |
| 1837 | 1836 |
| 1838 EXPECT_EQ(sync_manager_.GetNudgeDelayTimeDelta(syncer::PREFERENCES), | 1837 EXPECT_EQ(sync_manager_.GetNudgeDelayTimeDelta(PREFERENCES), |
| 1839 base::TimeDelta::FromMilliseconds( | 1838 base::TimeDelta::FromMilliseconds( |
| 1840 SyncManagerImpl::GetPreferencesNudgeDelay())); | 1839 SyncManagerImpl::GetPreferencesNudgeDelay())); |
| 1841 } | 1840 } |
| 1842 | 1841 |
| 1843 // Friended by WriteNode, so can't be in an anonymouse namespace. | 1842 // Friended by WriteNode, so can't be in an anonymouse namespace. |
| 1844 TEST_F(SyncManagerTest, EncryptBookmarksWithLegacyData) { | 1843 TEST_F(SyncManagerTest, EncryptBookmarksWithLegacyData) { |
| 1845 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1844 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 1846 std::string title; | 1845 std::string title; |
| 1847 SyncAPINameToServerName("Google", &title); | 1846 SyncAPINameToServerName("Google", &title); |
| 1848 std::string url = "http://www.google.com"; | 1847 std::string url = "http://www.google.com"; |
| 1849 std::string raw_title2 = ".."; // An invalid cosmo title. | 1848 std::string raw_title2 = ".."; // An invalid cosmo title. |
| 1850 std::string title2; | 1849 std::string title2; |
| 1851 SyncAPINameToServerName(raw_title2, &title2); | 1850 SyncAPINameToServerName(raw_title2, &title2); |
| 1852 std::string url2 = "http://www.bla.com"; | 1851 std::string url2 = "http://www.bla.com"; |
| 1853 | 1852 |
| 1854 // Create a bookmark using the legacy format. | 1853 // Create a bookmark using the legacy format. |
| 1855 int64 node_id1 = MakeNode(sync_manager_.GetUserShare(), | 1854 int64 node_id1 = MakeNode(sync_manager_.GetUserShare(), |
| 1856 syncer::BOOKMARKS, | 1855 BOOKMARKS, |
| 1857 "testtag"); | 1856 "testtag"); |
| 1858 int64 node_id2 = MakeNode(sync_manager_.GetUserShare(), | 1857 int64 node_id2 = MakeNode(sync_manager_.GetUserShare(), |
| 1859 syncer::BOOKMARKS, | 1858 BOOKMARKS, |
| 1860 "testtag2"); | 1859 "testtag2"); |
| 1861 { | 1860 { |
| 1862 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1861 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1863 WriteNode node(&trans); | 1862 WriteNode node(&trans); |
| 1864 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(node_id1)); | 1863 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(node_id1)); |
| 1865 | 1864 |
| 1866 sync_pb::EntitySpecifics entity_specifics; | 1865 sync_pb::EntitySpecifics entity_specifics; |
| 1867 entity_specifics.mutable_bookmark()->set_url(url); | 1866 entity_specifics.mutable_bookmark()->set_url(url); |
| 1868 node.SetEntitySpecifics(entity_specifics); | 1867 node.SetEntitySpecifics(entity_specifics); |
| 1869 | 1868 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1880 | 1879 |
| 1881 // Set the old style title. | 1880 // Set the old style title. |
| 1882 syncable::MutableEntry* node_entry2 = node2.entry_; | 1881 syncable::MutableEntry* node_entry2 = node2.entry_; |
| 1883 node_entry2->Put(syncable::NON_UNIQUE_NAME, title2); | 1882 node_entry2->Put(syncable::NON_UNIQUE_NAME, title2); |
| 1884 } | 1883 } |
| 1885 | 1884 |
| 1886 { | 1885 { |
| 1887 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1886 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1888 ReadNode node(&trans); | 1887 ReadNode node(&trans); |
| 1889 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(node_id1)); | 1888 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(node_id1)); |
| 1890 EXPECT_EQ(syncer::BOOKMARKS, node.GetModelType()); | 1889 EXPECT_EQ(BOOKMARKS, node.GetModelType()); |
| 1891 EXPECT_EQ(title, node.GetTitle()); | 1890 EXPECT_EQ(title, node.GetTitle()); |
| 1892 EXPECT_EQ(title, node.GetBookmarkSpecifics().title()); | 1891 EXPECT_EQ(title, node.GetBookmarkSpecifics().title()); |
| 1893 EXPECT_EQ(url, node.GetBookmarkSpecifics().url()); | 1892 EXPECT_EQ(url, node.GetBookmarkSpecifics().url()); |
| 1894 | 1893 |
| 1895 ReadNode node2(&trans); | 1894 ReadNode node2(&trans); |
| 1896 EXPECT_EQ(BaseNode::INIT_OK, node2.InitByIdLookup(node_id2)); | 1895 EXPECT_EQ(BaseNode::INIT_OK, node2.InitByIdLookup(node_id2)); |
| 1897 EXPECT_EQ(syncer::BOOKMARKS, node2.GetModelType()); | 1896 EXPECT_EQ(BOOKMARKS, node2.GetModelType()); |
| 1898 // We should de-canonicalize the title in GetTitle(), but the title in the | 1897 // We should de-canonicalize the title in GetTitle(), but the title in the |
| 1899 // specifics should be stored in the server legal form. | 1898 // specifics should be stored in the server legal form. |
| 1900 EXPECT_EQ(raw_title2, node2.GetTitle()); | 1899 EXPECT_EQ(raw_title2, node2.GetTitle()); |
| 1901 EXPECT_EQ(title2, node2.GetBookmarkSpecifics().title()); | 1900 EXPECT_EQ(title2, node2.GetBookmarkSpecifics().title()); |
| 1902 EXPECT_EQ(url2, node2.GetBookmarkSpecifics().url()); | 1901 EXPECT_EQ(url2, node2.GetBookmarkSpecifics().url()); |
| 1903 } | 1902 } |
| 1904 | 1903 |
| 1905 { | 1904 { |
| 1906 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1905 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1907 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1906 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1908 trans.GetWrappedTrans(), | 1907 trans.GetWrappedTrans(), |
| 1909 trans.GetCryptographer(), | 1908 trans.GetCryptographer(), |
| 1910 syncer::BOOKMARKS, | 1909 BOOKMARKS, |
| 1911 false /* not encrypted */)); | 1910 false /* not encrypted */)); |
| 1912 } | 1911 } |
| 1913 | 1912 |
| 1914 EXPECT_CALL(observer_, | 1913 EXPECT_CALL(observer_, |
| 1915 OnEncryptedTypesChanged( | 1914 OnEncryptedTypesChanged( |
| 1916 HasModelTypes(syncer::ModelTypeSet::All()), true)); | 1915 HasModelTypes(ModelTypeSet::All()), true)); |
| 1917 EXPECT_CALL(observer_, OnEncryptionComplete()); | 1916 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 1918 sync_manager_.EnableEncryptEverything(); | 1917 sync_manager_.EnableEncryptEverything(); |
| 1919 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabledForTest()); | 1918 EXPECT_TRUE(sync_manager_.EncryptEverythingEnabledForTest()); |
| 1920 | 1919 |
| 1921 { | 1920 { |
| 1922 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1921 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1923 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals(syncer::ModelTypeSet::All())); | 1922 EXPECT_TRUE(GetEncryptedTypes(&trans).Equals(ModelTypeSet::All())); |
| 1924 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1923 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1925 trans.GetWrappedTrans(), | 1924 trans.GetWrappedTrans(), |
| 1926 trans.GetCryptographer(), | 1925 trans.GetCryptographer(), |
| 1927 syncer::BOOKMARKS, | 1926 BOOKMARKS, |
| 1928 true /* is encrypted */)); | 1927 true /* is encrypted */)); |
| 1929 | 1928 |
| 1930 ReadNode node(&trans); | 1929 ReadNode node(&trans); |
| 1931 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(node_id1)); | 1930 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(node_id1)); |
| 1932 EXPECT_EQ(syncer::BOOKMARKS, node.GetModelType()); | 1931 EXPECT_EQ(BOOKMARKS, node.GetModelType()); |
| 1933 EXPECT_EQ(title, node.GetTitle()); | 1932 EXPECT_EQ(title, node.GetTitle()); |
| 1934 EXPECT_EQ(title, node.GetBookmarkSpecifics().title()); | 1933 EXPECT_EQ(title, node.GetBookmarkSpecifics().title()); |
| 1935 EXPECT_EQ(url, node.GetBookmarkSpecifics().url()); | 1934 EXPECT_EQ(url, node.GetBookmarkSpecifics().url()); |
| 1936 | 1935 |
| 1937 ReadNode node2(&trans); | 1936 ReadNode node2(&trans); |
| 1938 EXPECT_EQ(BaseNode::INIT_OK, node2.InitByIdLookup(node_id2)); | 1937 EXPECT_EQ(BaseNode::INIT_OK, node2.InitByIdLookup(node_id2)); |
| 1939 EXPECT_EQ(syncer::BOOKMARKS, node2.GetModelType()); | 1938 EXPECT_EQ(BOOKMARKS, node2.GetModelType()); |
| 1940 // We should de-canonicalize the title in GetTitle(), but the title in the | 1939 // We should de-canonicalize the title in GetTitle(), but the title in the |
| 1941 // specifics should be stored in the server legal form. | 1940 // specifics should be stored in the server legal form. |
| 1942 EXPECT_EQ(raw_title2, node2.GetTitle()); | 1941 EXPECT_EQ(raw_title2, node2.GetTitle()); |
| 1943 EXPECT_EQ(title2, node2.GetBookmarkSpecifics().title()); | 1942 EXPECT_EQ(title2, node2.GetBookmarkSpecifics().title()); |
| 1944 EXPECT_EQ(url2, node2.GetBookmarkSpecifics().url()); | 1943 EXPECT_EQ(url2, node2.GetBookmarkSpecifics().url()); |
| 1945 } | 1944 } |
| 1946 } | 1945 } |
| 1947 | 1946 |
| 1948 // Create a bookmark and set the title/url, then verify the data was properly | 1947 // Create a bookmark and set the title/url, then verify the data was properly |
| 1949 // set. This replicates the unique way bookmarks have of creating sync nodes. | 1948 // set. This replicates the unique way bookmarks have of creating sync nodes. |
| 1950 // See BookmarkChangeProcessor::PlaceSyncNode(..). | 1949 // See BookmarkChangeProcessor::PlaceSyncNode(..). |
| 1951 TEST_F(SyncManagerTest, CreateLocalBookmark) { | 1950 TEST_F(SyncManagerTest, CreateLocalBookmark) { |
| 1952 std::string title = "title"; | 1951 std::string title = "title"; |
| 1953 GURL url("url"); | 1952 GURL url("url"); |
| 1954 { | 1953 { |
| 1955 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1954 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1956 ReadNode root_node(&trans); | 1955 ReadNode root_node(&trans); |
| 1957 root_node.InitByRootLookup(); | 1956 root_node.InitByRootLookup(); |
| 1958 WriteNode node(&trans); | 1957 WriteNode node(&trans); |
| 1959 ASSERT_TRUE(node.InitByCreation(syncer::BOOKMARKS, root_node, NULL)); | 1958 ASSERT_TRUE(node.InitByCreation(BOOKMARKS, root_node, NULL)); |
| 1960 node.SetIsFolder(false); | 1959 node.SetIsFolder(false); |
| 1961 node.SetTitle(UTF8ToWide(title)); | 1960 node.SetTitle(UTF8ToWide(title)); |
| 1962 node.SetURL(url); | 1961 node.SetURL(url); |
| 1963 } | 1962 } |
| 1964 { | 1963 { |
| 1965 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1964 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1966 ReadNode root_node(&trans); | 1965 ReadNode root_node(&trans); |
| 1967 root_node.InitByRootLookup(); | 1966 root_node.InitByRootLookup(); |
| 1968 int64 child_id = root_node.GetFirstChildId(); | 1967 int64 child_id = root_node.GetFirstChildId(); |
| 1969 | 1968 |
| 1970 ReadNode node(&trans); | 1969 ReadNode node(&trans); |
| 1971 ASSERT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); | 1970 ASSERT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); |
| 1972 EXPECT_FALSE(node.GetIsFolder()); | 1971 EXPECT_FALSE(node.GetIsFolder()); |
| 1973 EXPECT_EQ(title, node.GetTitle()); | 1972 EXPECT_EQ(title, node.GetTitle()); |
| 1974 EXPECT_EQ(url, node.GetURL()); | 1973 EXPECT_EQ(url, node.GetURL()); |
| 1975 } | 1974 } |
| 1976 } | 1975 } |
| 1977 | 1976 |
| 1978 // Verifies WriteNode::UpdateEntryWithEncryption does not make unnecessary | 1977 // Verifies WriteNode::UpdateEntryWithEncryption does not make unnecessary |
| 1979 // changes. | 1978 // changes. |
| 1980 TEST_F(SyncManagerTest, UpdateEntryWithEncryption) { | 1979 TEST_F(SyncManagerTest, UpdateEntryWithEncryption) { |
| 1981 std::string client_tag = "title"; | 1980 std::string client_tag = "title"; |
| 1982 sync_pb::EntitySpecifics entity_specifics; | 1981 sync_pb::EntitySpecifics entity_specifics; |
| 1983 entity_specifics.mutable_bookmark()->set_url("url"); | 1982 entity_specifics.mutable_bookmark()->set_url("url"); |
| 1984 entity_specifics.mutable_bookmark()->set_title("title"); | 1983 entity_specifics.mutable_bookmark()->set_title("title"); |
| 1985 MakeServerNode(sync_manager_.GetUserShare(), syncer::BOOKMARKS, client_tag, | 1984 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, |
| 1986 BaseNode::GenerateSyncableHash(syncer::BOOKMARKS, | 1985 BaseNode::GenerateSyncableHash(BOOKMARKS, |
| 1987 client_tag), | 1986 client_tag), |
| 1988 entity_specifics); | 1987 entity_specifics); |
| 1989 // New node shouldn't start off unsynced. | 1988 // New node shouldn't start off unsynced. |
| 1990 EXPECT_FALSE(ResetUnsyncedEntry(syncer::BOOKMARKS, client_tag)); | 1989 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 1991 // Manually change to the same data. Should not set is_unsynced. | 1990 // Manually change to the same data. Should not set is_unsynced. |
| 1992 { | 1991 { |
| 1993 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1992 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1994 WriteNode node(&trans); | 1993 WriteNode node(&trans); |
| 1995 EXPECT_EQ(BaseNode::INIT_OK, | 1994 EXPECT_EQ(BaseNode::INIT_OK, |
| 1996 node.InitByClientTagLookup(syncer::BOOKMARKS, client_tag)); | 1995 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 1997 node.SetEntitySpecifics(entity_specifics); | 1996 node.SetEntitySpecifics(entity_specifics); |
| 1998 } | 1997 } |
| 1999 EXPECT_FALSE(ResetUnsyncedEntry(syncer::BOOKMARKS, client_tag)); | 1998 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2000 | 1999 |
| 2001 // Encrypt the datatatype, should set is_unsynced. | 2000 // Encrypt the datatatype, should set is_unsynced. |
| 2002 EXPECT_CALL(observer_, | 2001 EXPECT_CALL(observer_, |
| 2003 OnEncryptedTypesChanged( | 2002 OnEncryptedTypesChanged( |
| 2004 HasModelTypes(syncer::ModelTypeSet::All()), true)); | 2003 HasModelTypes(ModelTypeSet::All()), true)); |
| 2005 EXPECT_CALL(observer_, OnEncryptionComplete()); | 2004 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 2006 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); | 2005 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); |
| 2007 | 2006 |
| 2008 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); | 2007 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); |
| 2009 PumpLoop(); | 2008 PumpLoop(); |
| 2010 { | 2009 { |
| 2011 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2010 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2012 ReadNode node(&trans); | 2011 ReadNode node(&trans); |
| 2013 EXPECT_EQ(BaseNode::INIT_OK, | 2012 EXPECT_EQ(BaseNode::INIT_OK, |
| 2014 node.InitByClientTagLookup(syncer::BOOKMARKS, client_tag)); | 2013 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 2015 const syncable::Entry* node_entry = node.GetEntry(); | 2014 const syncable::Entry* node_entry = node.GetEntry(); |
| 2016 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2015 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
| 2017 EXPECT_TRUE(specifics.has_encrypted()); | 2016 EXPECT_TRUE(specifics.has_encrypted()); |
| 2018 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2017 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
| 2019 Cryptographer* cryptographer = trans.GetCryptographer(); | 2018 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2020 EXPECT_TRUE(cryptographer->is_ready()); | 2019 EXPECT_TRUE(cryptographer->is_ready()); |
| 2021 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 2020 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( |
| 2022 specifics.encrypted())); | 2021 specifics.encrypted())); |
| 2023 } | 2022 } |
| 2024 EXPECT_TRUE(ResetUnsyncedEntry(syncer::BOOKMARKS, client_tag)); | 2023 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2025 | 2024 |
| 2026 // Set a new passphrase. Should set is_unsynced. | 2025 // Set a new passphrase. Should set is_unsynced. |
| 2027 testing::Mock::VerifyAndClearExpectations(&observer_); | 2026 testing::Mock::VerifyAndClearExpectations(&observer_); |
| 2028 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); | 2027 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); |
| 2029 EXPECT_CALL(observer_, OnPassphraseAccepted()); | 2028 EXPECT_CALL(observer_, OnPassphraseAccepted()); |
| 2030 EXPECT_CALL(observer_, OnEncryptionComplete()); | 2029 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 2031 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); | 2030 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); |
| 2032 { | 2031 { |
| 2033 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2032 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2034 ReadNode node(&trans); | 2033 ReadNode node(&trans); |
| 2035 EXPECT_EQ(BaseNode::INIT_OK, | 2034 EXPECT_EQ(BaseNode::INIT_OK, |
| 2036 node.InitByClientTagLookup(syncer::BOOKMARKS, client_tag)); | 2035 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 2037 const syncable::Entry* node_entry = node.GetEntry(); | 2036 const syncable::Entry* node_entry = node.GetEntry(); |
| 2038 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2037 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
| 2039 EXPECT_TRUE(specifics.has_encrypted()); | 2038 EXPECT_TRUE(specifics.has_encrypted()); |
| 2040 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2039 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
| 2041 Cryptographer* cryptographer = trans.GetCryptographer(); | 2040 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2042 EXPECT_TRUE(cryptographer->is_ready()); | 2041 EXPECT_TRUE(cryptographer->is_ready()); |
| 2043 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 2042 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( |
| 2044 specifics.encrypted())); | 2043 specifics.encrypted())); |
| 2045 } | 2044 } |
| 2046 EXPECT_TRUE(ResetUnsyncedEntry(syncer::BOOKMARKS, client_tag)); | 2045 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2047 | 2046 |
| 2048 // Force a re-encrypt everything. Should not set is_unsynced. | 2047 // Force a re-encrypt everything. Should not set is_unsynced. |
| 2049 testing::Mock::VerifyAndClearExpectations(&observer_); | 2048 testing::Mock::VerifyAndClearExpectations(&observer_); |
| 2050 EXPECT_CALL(observer_, OnEncryptionComplete()); | 2049 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 2051 | 2050 |
| 2052 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); | 2051 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); |
| 2053 PumpLoop(); | 2052 PumpLoop(); |
| 2054 | 2053 |
| 2055 { | 2054 { |
| 2056 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2055 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2057 ReadNode node(&trans); | 2056 ReadNode node(&trans); |
| 2058 EXPECT_EQ(BaseNode::INIT_OK, | 2057 EXPECT_EQ(BaseNode::INIT_OK, |
| 2059 node.InitByClientTagLookup(syncer::BOOKMARKS, client_tag)); | 2058 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 2060 const syncable::Entry* node_entry = node.GetEntry(); | 2059 const syncable::Entry* node_entry = node.GetEntry(); |
| 2061 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2060 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
| 2062 EXPECT_TRUE(specifics.has_encrypted()); | 2061 EXPECT_TRUE(specifics.has_encrypted()); |
| 2063 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2062 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
| 2064 Cryptographer* cryptographer = trans.GetCryptographer(); | 2063 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2065 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 2064 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( |
| 2066 specifics.encrypted())); | 2065 specifics.encrypted())); |
| 2067 } | 2066 } |
| 2068 EXPECT_FALSE(ResetUnsyncedEntry(syncer::BOOKMARKS, client_tag)); | 2067 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2069 | 2068 |
| 2070 // Manually change to the same data. Should not set is_unsynced. | 2069 // Manually change to the same data. Should not set is_unsynced. |
| 2071 { | 2070 { |
| 2072 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2071 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2073 WriteNode node(&trans); | 2072 WriteNode node(&trans); |
| 2074 EXPECT_EQ(BaseNode::INIT_OK, | 2073 EXPECT_EQ(BaseNode::INIT_OK, |
| 2075 node.InitByClientTagLookup(syncer::BOOKMARKS, client_tag)); | 2074 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 2076 node.SetEntitySpecifics(entity_specifics); | 2075 node.SetEntitySpecifics(entity_specifics); |
| 2077 const syncable::Entry* node_entry = node.GetEntry(); | 2076 const syncable::Entry* node_entry = node.GetEntry(); |
| 2078 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2077 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
| 2079 EXPECT_TRUE(specifics.has_encrypted()); | 2078 EXPECT_TRUE(specifics.has_encrypted()); |
| 2080 EXPECT_FALSE(node_entry->Get(IS_UNSYNCED)); | 2079 EXPECT_FALSE(node_entry->Get(IS_UNSYNCED)); |
| 2081 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2080 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
| 2082 Cryptographer* cryptographer = trans.GetCryptographer(); | 2081 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2083 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 2082 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( |
| 2084 specifics.encrypted())); | 2083 specifics.encrypted())); |
| 2085 } | 2084 } |
| 2086 EXPECT_FALSE(ResetUnsyncedEntry(syncer::BOOKMARKS, client_tag)); | 2085 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2087 | 2086 |
| 2088 // Manually change to different data. Should set is_unsynced. | 2087 // Manually change to different data. Should set is_unsynced. |
| 2089 { | 2088 { |
| 2090 entity_specifics.mutable_bookmark()->set_url("url2"); | 2089 entity_specifics.mutable_bookmark()->set_url("url2"); |
| 2091 entity_specifics.mutable_bookmark()->set_title("title2"); | 2090 entity_specifics.mutable_bookmark()->set_title("title2"); |
| 2092 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2091 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2093 WriteNode node(&trans); | 2092 WriteNode node(&trans); |
| 2094 EXPECT_EQ(BaseNode::INIT_OK, | 2093 EXPECT_EQ(BaseNode::INIT_OK, |
| 2095 node.InitByClientTagLookup(syncer::BOOKMARKS, client_tag)); | 2094 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 2096 node.SetEntitySpecifics(entity_specifics); | 2095 node.SetEntitySpecifics(entity_specifics); |
| 2097 const syncable::Entry* node_entry = node.GetEntry(); | 2096 const syncable::Entry* node_entry = node.GetEntry(); |
| 2098 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2097 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
| 2099 EXPECT_TRUE(specifics.has_encrypted()); | 2098 EXPECT_TRUE(specifics.has_encrypted()); |
| 2100 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED)); | 2099 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED)); |
| 2101 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2100 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
| 2102 Cryptographer* cryptographer = trans.GetCryptographer(); | 2101 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2103 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 2102 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( |
| 2104 specifics.encrypted())); | 2103 specifics.encrypted())); |
| 2105 } | 2104 } |
| 2106 } | 2105 } |
| 2107 | 2106 |
| 2108 // Passwords have their own handling for encryption. Verify it does not result | 2107 // Passwords have their own handling for encryption. Verify it does not result |
| 2109 // in unnecessary writes via SetEntitySpecifics. | 2108 // in unnecessary writes via SetEntitySpecifics. |
| 2110 TEST_F(SyncManagerTest, UpdatePasswordSetEntitySpecificsNoChange) { | 2109 TEST_F(SyncManagerTest, UpdatePasswordSetEntitySpecificsNoChange) { |
| 2111 std::string client_tag = "title"; | 2110 std::string client_tag = "title"; |
| 2112 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2111 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2113 sync_pb::EntitySpecifics entity_specifics; | 2112 sync_pb::EntitySpecifics entity_specifics; |
| 2114 { | 2113 { |
| 2115 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2114 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2116 Cryptographer* cryptographer = trans.GetCryptographer(); | 2115 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2117 sync_pb::PasswordSpecificsData data; | 2116 sync_pb::PasswordSpecificsData data; |
| 2118 data.set_password_value("secret"); | 2117 data.set_password_value("secret"); |
| 2119 cryptographer->Encrypt( | 2118 cryptographer->Encrypt( |
| 2120 data, | 2119 data, |
| 2121 entity_specifics.mutable_password()-> | 2120 entity_specifics.mutable_password()-> |
| 2122 mutable_encrypted()); | 2121 mutable_encrypted()); |
| 2123 } | 2122 } |
| 2124 MakeServerNode(sync_manager_.GetUserShare(), syncer::PASSWORDS, client_tag, | 2123 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, |
| 2125 BaseNode::GenerateSyncableHash(syncer::PASSWORDS, | 2124 BaseNode::GenerateSyncableHash(PASSWORDS, |
| 2126 client_tag), | 2125 client_tag), |
| 2127 entity_specifics); | 2126 entity_specifics); |
| 2128 // New node shouldn't start off unsynced. | 2127 // New node shouldn't start off unsynced. |
| 2129 EXPECT_FALSE(ResetUnsyncedEntry(syncer::PASSWORDS, client_tag)); | 2128 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2130 | 2129 |
| 2131 // Manually change to the same data via SetEntitySpecifics. Should not set | 2130 // Manually change to the same data via SetEntitySpecifics. Should not set |
| 2132 // is_unsynced. | 2131 // is_unsynced. |
| 2133 { | 2132 { |
| 2134 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2133 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2135 WriteNode node(&trans); | 2134 WriteNode node(&trans); |
| 2136 EXPECT_EQ(BaseNode::INIT_OK, | 2135 EXPECT_EQ(BaseNode::INIT_OK, |
| 2137 node.InitByClientTagLookup(syncer::PASSWORDS, client_tag)); | 2136 node.InitByClientTagLookup(PASSWORDS, client_tag)); |
| 2138 node.SetEntitySpecifics(entity_specifics); | 2137 node.SetEntitySpecifics(entity_specifics); |
| 2139 } | 2138 } |
| 2140 EXPECT_FALSE(ResetUnsyncedEntry(syncer::PASSWORDS, client_tag)); | 2139 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2141 } | 2140 } |
| 2142 | 2141 |
| 2143 // Passwords have their own handling for encryption. Verify it does not result | 2142 // Passwords have their own handling for encryption. Verify it does not result |
| 2144 // in unnecessary writes via SetPasswordSpecifics. | 2143 // in unnecessary writes via SetPasswordSpecifics. |
| 2145 TEST_F(SyncManagerTest, UpdatePasswordSetPasswordSpecifics) { | 2144 TEST_F(SyncManagerTest, UpdatePasswordSetPasswordSpecifics) { |
| 2146 std::string client_tag = "title"; | 2145 std::string client_tag = "title"; |
| 2147 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2146 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2148 sync_pb::EntitySpecifics entity_specifics; | 2147 sync_pb::EntitySpecifics entity_specifics; |
| 2149 { | 2148 { |
| 2150 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2149 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2151 Cryptographer* cryptographer = trans.GetCryptographer(); | 2150 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2152 sync_pb::PasswordSpecificsData data; | 2151 sync_pb::PasswordSpecificsData data; |
| 2153 data.set_password_value("secret"); | 2152 data.set_password_value("secret"); |
| 2154 cryptographer->Encrypt( | 2153 cryptographer->Encrypt( |
| 2155 data, | 2154 data, |
| 2156 entity_specifics.mutable_password()-> | 2155 entity_specifics.mutable_password()-> |
| 2157 mutable_encrypted()); | 2156 mutable_encrypted()); |
| 2158 } | 2157 } |
| 2159 MakeServerNode(sync_manager_.GetUserShare(), syncer::PASSWORDS, client_tag, | 2158 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, |
| 2160 BaseNode::GenerateSyncableHash(syncer::PASSWORDS, | 2159 BaseNode::GenerateSyncableHash(PASSWORDS, |
| 2161 client_tag), | 2160 client_tag), |
| 2162 entity_specifics); | 2161 entity_specifics); |
| 2163 // New node shouldn't start off unsynced. | 2162 // New node shouldn't start off unsynced. |
| 2164 EXPECT_FALSE(ResetUnsyncedEntry(syncer::PASSWORDS, client_tag)); | 2163 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2165 | 2164 |
| 2166 // Manually change to the same data via SetPasswordSpecifics. Should not set | 2165 // Manually change to the same data via SetPasswordSpecifics. Should not set |
| 2167 // is_unsynced. | 2166 // is_unsynced. |
| 2168 { | 2167 { |
| 2169 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2168 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2170 WriteNode node(&trans); | 2169 WriteNode node(&trans); |
| 2171 EXPECT_EQ(BaseNode::INIT_OK, | 2170 EXPECT_EQ(BaseNode::INIT_OK, |
| 2172 node.InitByClientTagLookup(syncer::PASSWORDS, client_tag)); | 2171 node.InitByClientTagLookup(PASSWORDS, client_tag)); |
| 2173 node.SetPasswordSpecifics(node.GetPasswordSpecifics()); | 2172 node.SetPasswordSpecifics(node.GetPasswordSpecifics()); |
| 2174 } | 2173 } |
| 2175 EXPECT_FALSE(ResetUnsyncedEntry(syncer::PASSWORDS, client_tag)); | 2174 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2176 | 2175 |
| 2177 // Manually change to different data. Should set is_unsynced. | 2176 // Manually change to different data. Should set is_unsynced. |
| 2178 { | 2177 { |
| 2179 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2178 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2180 WriteNode node(&trans); | 2179 WriteNode node(&trans); |
| 2181 EXPECT_EQ(BaseNode::INIT_OK, | 2180 EXPECT_EQ(BaseNode::INIT_OK, |
| 2182 node.InitByClientTagLookup(syncer::PASSWORDS, client_tag)); | 2181 node.InitByClientTagLookup(PASSWORDS, client_tag)); |
| 2183 Cryptographer* cryptographer = trans.GetCryptographer(); | 2182 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2184 sync_pb::PasswordSpecificsData data; | 2183 sync_pb::PasswordSpecificsData data; |
| 2185 data.set_password_value("secret2"); | 2184 data.set_password_value("secret2"); |
| 2186 cryptographer->Encrypt( | 2185 cryptographer->Encrypt( |
| 2187 data, | 2186 data, |
| 2188 entity_specifics.mutable_password()->mutable_encrypted()); | 2187 entity_specifics.mutable_password()->mutable_encrypted()); |
| 2189 node.SetPasswordSpecifics(data); | 2188 node.SetPasswordSpecifics(data); |
| 2190 const syncable::Entry* node_entry = node.GetEntry(); | 2189 const syncable::Entry* node_entry = node.GetEntry(); |
| 2191 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED)); | 2190 EXPECT_TRUE(node_entry->Get(IS_UNSYNCED)); |
| 2192 } | 2191 } |
| 2193 } | 2192 } |
| 2194 | 2193 |
| 2195 // Passwords have their own handling for encryption. Verify setting a new | 2194 // Passwords have their own handling for encryption. Verify setting a new |
| 2196 // passphrase updates the data. | 2195 // passphrase updates the data. |
| 2197 TEST_F(SyncManagerTest, UpdatePasswordNewPassphrase) { | 2196 TEST_F(SyncManagerTest, UpdatePasswordNewPassphrase) { |
| 2198 std::string client_tag = "title"; | 2197 std::string client_tag = "title"; |
| 2199 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2198 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2200 sync_pb::EntitySpecifics entity_specifics; | 2199 sync_pb::EntitySpecifics entity_specifics; |
| 2201 { | 2200 { |
| 2202 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2201 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2203 Cryptographer* cryptographer = trans.GetCryptographer(); | 2202 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2204 sync_pb::PasswordSpecificsData data; | 2203 sync_pb::PasswordSpecificsData data; |
| 2205 data.set_password_value("secret"); | 2204 data.set_password_value("secret"); |
| 2206 cryptographer->Encrypt( | 2205 cryptographer->Encrypt( |
| 2207 data, | 2206 data, |
| 2208 entity_specifics.mutable_password()->mutable_encrypted()); | 2207 entity_specifics.mutable_password()->mutable_encrypted()); |
| 2209 } | 2208 } |
| 2210 MakeServerNode(sync_manager_.GetUserShare(), syncer::PASSWORDS, client_tag, | 2209 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, |
| 2211 BaseNode::GenerateSyncableHash(syncer::PASSWORDS, | 2210 BaseNode::GenerateSyncableHash(PASSWORDS, |
| 2212 client_tag), | 2211 client_tag), |
| 2213 entity_specifics); | 2212 entity_specifics); |
| 2214 // New node shouldn't start off unsynced. | 2213 // New node shouldn't start off unsynced. |
| 2215 EXPECT_FALSE(ResetUnsyncedEntry(syncer::PASSWORDS, client_tag)); | 2214 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2216 | 2215 |
| 2217 // Set a new passphrase. Should set is_unsynced. | 2216 // Set a new passphrase. Should set is_unsynced. |
| 2218 testing::Mock::VerifyAndClearExpectations(&observer_); | 2217 testing::Mock::VerifyAndClearExpectations(&observer_); |
| 2219 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); | 2218 EXPECT_CALL(observer_, OnBootstrapTokenUpdated(_)); |
| 2220 EXPECT_CALL(observer_, OnPassphraseAccepted()); | 2219 EXPECT_CALL(observer_, OnPassphraseAccepted()); |
| 2221 EXPECT_CALL(observer_, OnEncryptionComplete()); | 2220 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 2222 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); | 2221 sync_manager_.SetEncryptionPassphrase("new_passphrase", true); |
| 2223 EXPECT_TRUE(ResetUnsyncedEntry(syncer::PASSWORDS, client_tag)); | 2222 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2224 } | 2223 } |
| 2225 | 2224 |
| 2226 // Passwords have their own handling for encryption. Verify it does not result | 2225 // Passwords have their own handling for encryption. Verify it does not result |
| 2227 // in unnecessary writes via ReencryptEverything. | 2226 // in unnecessary writes via ReencryptEverything. |
| 2228 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) { | 2227 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) { |
| 2229 std::string client_tag = "title"; | 2228 std::string client_tag = "title"; |
| 2230 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2229 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2231 sync_pb::EntitySpecifics entity_specifics; | 2230 sync_pb::EntitySpecifics entity_specifics; |
| 2232 { | 2231 { |
| 2233 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2232 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2234 Cryptographer* cryptographer = trans.GetCryptographer(); | 2233 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2235 sync_pb::PasswordSpecificsData data; | 2234 sync_pb::PasswordSpecificsData data; |
| 2236 data.set_password_value("secret"); | 2235 data.set_password_value("secret"); |
| 2237 cryptographer->Encrypt( | 2236 cryptographer->Encrypt( |
| 2238 data, | 2237 data, |
| 2239 entity_specifics.mutable_password()->mutable_encrypted()); | 2238 entity_specifics.mutable_password()->mutable_encrypted()); |
| 2240 } | 2239 } |
| 2241 MakeServerNode(sync_manager_.GetUserShare(), syncer::PASSWORDS, client_tag, | 2240 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, |
| 2242 BaseNode::GenerateSyncableHash(syncer::PASSWORDS, | 2241 BaseNode::GenerateSyncableHash(PASSWORDS, |
| 2243 client_tag), | 2242 client_tag), |
| 2244 entity_specifics); | 2243 entity_specifics); |
| 2245 // New node shouldn't start off unsynced. | 2244 // New node shouldn't start off unsynced. |
| 2246 EXPECT_FALSE(ResetUnsyncedEntry(syncer::PASSWORDS, client_tag)); | 2245 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2247 | 2246 |
| 2248 // Force a re-encrypt everything. Should not set is_unsynced. | 2247 // Force a re-encrypt everything. Should not set is_unsynced. |
| 2249 testing::Mock::VerifyAndClearExpectations(&observer_); | 2248 testing::Mock::VerifyAndClearExpectations(&observer_); |
| 2250 EXPECT_CALL(observer_, OnEncryptionComplete()); | 2249 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 2251 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); | 2250 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); |
| 2252 PumpLoop(); | 2251 PumpLoop(); |
| 2253 EXPECT_FALSE(ResetUnsyncedEntry(syncer::PASSWORDS, client_tag)); | 2252 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2254 } | 2253 } |
| 2255 | 2254 |
| 2256 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for bookmarks | 2255 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for bookmarks |
| 2257 // when we write the same data, but does set it when we write new data. | 2256 // when we write the same data, but does set it when we write new data. |
| 2258 TEST_F(SyncManagerTest, SetBookmarkTitle) { | 2257 TEST_F(SyncManagerTest, SetBookmarkTitle) { |
| 2259 std::string client_tag = "title"; | 2258 std::string client_tag = "title"; |
| 2260 sync_pb::EntitySpecifics entity_specifics; | 2259 sync_pb::EntitySpecifics entity_specifics; |
| 2261 entity_specifics.mutable_bookmark()->set_url("url"); | 2260 entity_specifics.mutable_bookmark()->set_url("url"); |
| 2262 entity_specifics.mutable_bookmark()->set_title("title"); | 2261 entity_specifics.mutable_bookmark()->set_title("title"); |
| 2263 MakeServerNode(sync_manager_.GetUserShare(), syncer::BOOKMARKS, client_tag, | 2262 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, |
| 2264 BaseNode::GenerateSyncableHash(syncer::BOOKMARKS, | 2263 BaseNode::GenerateSyncableHash(BOOKMARKS, |
| 2265 client_tag), | 2264 client_tag), |
| 2266 entity_specifics); | 2265 entity_specifics); |
| 2267 // New node shouldn't start off unsynced. | 2266 // New node shouldn't start off unsynced. |
| 2268 EXPECT_FALSE(ResetUnsyncedEntry(syncer::BOOKMARKS, client_tag)); | 2267 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2269 | 2268 |
| 2270 // Manually change to the same title. Should not set is_unsynced. | 2269 // Manually change to the same title. Should not set is_unsynced. |
| 2271 { | 2270 { |
| 2272 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2271 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2273 WriteNode node(&trans); | 2272 WriteNode node(&trans); |
| 2274 EXPECT_EQ(BaseNode::INIT_OK, | 2273 EXPECT_EQ(BaseNode::INIT_OK, |
| 2275 node.InitByClientTagLookup(syncer::BOOKMARKS, client_tag)); | 2274 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 2276 node.SetTitle(UTF8ToWide(client_tag)); | 2275 node.SetTitle(UTF8ToWide(client_tag)); |
| 2277 } | 2276 } |
| 2278 EXPECT_FALSE(ResetUnsyncedEntry(syncer::BOOKMARKS, client_tag)); | 2277 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2279 | 2278 |
| 2280 // Manually change to new title. Should set is_unsynced. | 2279 // Manually change to new title. Should set is_unsynced. |
| 2281 { | 2280 { |
| 2282 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2281 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2283 WriteNode node(&trans); | 2282 WriteNode node(&trans); |
| 2284 EXPECT_EQ(BaseNode::INIT_OK, | 2283 EXPECT_EQ(BaseNode::INIT_OK, |
| 2285 node.InitByClientTagLookup(syncer::BOOKMARKS, client_tag)); | 2284 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 2286 node.SetTitle(UTF8ToWide("title2")); | 2285 node.SetTitle(UTF8ToWide("title2")); |
| 2287 } | 2286 } |
| 2288 EXPECT_TRUE(ResetUnsyncedEntry(syncer::BOOKMARKS, client_tag)); | 2287 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2289 } | 2288 } |
| 2290 | 2289 |
| 2291 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted | 2290 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted |
| 2292 // bookmarks when we write the same data, but does set it when we write new | 2291 // bookmarks when we write the same data, but does set it when we write new |
| 2293 // data. | 2292 // data. |
| 2294 TEST_F(SyncManagerTest, SetBookmarkTitleWithEncryption) { | 2293 TEST_F(SyncManagerTest, SetBookmarkTitleWithEncryption) { |
| 2295 std::string client_tag = "title"; | 2294 std::string client_tag = "title"; |
| 2296 sync_pb::EntitySpecifics entity_specifics; | 2295 sync_pb::EntitySpecifics entity_specifics; |
| 2297 entity_specifics.mutable_bookmark()->set_url("url"); | 2296 entity_specifics.mutable_bookmark()->set_url("url"); |
| 2298 entity_specifics.mutable_bookmark()->set_title("title"); | 2297 entity_specifics.mutable_bookmark()->set_title("title"); |
| 2299 MakeServerNode(sync_manager_.GetUserShare(), syncer::BOOKMARKS, client_tag, | 2298 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, |
| 2300 BaseNode::GenerateSyncableHash(syncer::BOOKMARKS, | 2299 BaseNode::GenerateSyncableHash(BOOKMARKS, |
| 2301 client_tag), | 2300 client_tag), |
| 2302 entity_specifics); | 2301 entity_specifics); |
| 2303 // New node shouldn't start off unsynced. | 2302 // New node shouldn't start off unsynced. |
| 2304 EXPECT_FALSE(ResetUnsyncedEntry(syncer::BOOKMARKS, client_tag)); | 2303 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2305 | 2304 |
| 2306 // Encrypt the datatatype, should set is_unsynced. | 2305 // Encrypt the datatatype, should set is_unsynced. |
| 2307 EXPECT_CALL(observer_, | 2306 EXPECT_CALL(observer_, |
| 2308 OnEncryptedTypesChanged( | 2307 OnEncryptedTypesChanged( |
| 2309 HasModelTypes(syncer::ModelTypeSet::All()), true)); | 2308 HasModelTypes(ModelTypeSet::All()), true)); |
| 2310 EXPECT_CALL(observer_, OnEncryptionComplete()); | 2309 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 2311 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); | 2310 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); |
| 2312 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); | 2311 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); |
| 2313 PumpLoop(); | 2312 PumpLoop(); |
| 2314 EXPECT_TRUE(ResetUnsyncedEntry(syncer::BOOKMARKS, client_tag)); | 2313 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2315 | 2314 |
| 2316 // Manually change to the same title. Should not set is_unsynced. | 2315 // Manually change to the same title. Should not set is_unsynced. |
| 2317 // NON_UNIQUE_NAME should be kEncryptedString. | 2316 // NON_UNIQUE_NAME should be kEncryptedString. |
| 2318 { | 2317 { |
| 2319 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2318 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2320 WriteNode node(&trans); | 2319 WriteNode node(&trans); |
| 2321 EXPECT_EQ(BaseNode::INIT_OK, | 2320 EXPECT_EQ(BaseNode::INIT_OK, |
| 2322 node.InitByClientTagLookup(syncer::BOOKMARKS, client_tag)); | 2321 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 2323 node.SetTitle(UTF8ToWide(client_tag)); | 2322 node.SetTitle(UTF8ToWide(client_tag)); |
| 2324 const syncable::Entry* node_entry = node.GetEntry(); | 2323 const syncable::Entry* node_entry = node.GetEntry(); |
| 2325 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2324 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
| 2326 EXPECT_TRUE(specifics.has_encrypted()); | 2325 EXPECT_TRUE(specifics.has_encrypted()); |
| 2327 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2326 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
| 2328 } | 2327 } |
| 2329 EXPECT_FALSE(ResetUnsyncedEntry(syncer::BOOKMARKS, client_tag)); | 2328 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2330 | 2329 |
| 2331 // Manually change to new title. Should set is_unsynced. NON_UNIQUE_NAME | 2330 // Manually change to new title. Should set is_unsynced. NON_UNIQUE_NAME |
| 2332 // should still be kEncryptedString. | 2331 // should still be kEncryptedString. |
| 2333 { | 2332 { |
| 2334 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2333 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2335 WriteNode node(&trans); | 2334 WriteNode node(&trans); |
| 2336 EXPECT_EQ(BaseNode::INIT_OK, | 2335 EXPECT_EQ(BaseNode::INIT_OK, |
| 2337 node.InitByClientTagLookup(syncer::BOOKMARKS, client_tag)); | 2336 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 2338 node.SetTitle(UTF8ToWide("title2")); | 2337 node.SetTitle(UTF8ToWide("title2")); |
| 2339 const syncable::Entry* node_entry = node.GetEntry(); | 2338 const syncable::Entry* node_entry = node.GetEntry(); |
| 2340 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2339 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
| 2341 EXPECT_TRUE(specifics.has_encrypted()); | 2340 EXPECT_TRUE(specifics.has_encrypted()); |
| 2342 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2341 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
| 2343 } | 2342 } |
| 2344 EXPECT_TRUE(ResetUnsyncedEntry(syncer::BOOKMARKS, client_tag)); | 2343 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2345 } | 2344 } |
| 2346 | 2345 |
| 2347 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for non-bookmarks | 2346 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for non-bookmarks |
| 2348 // when we write the same data, but does set it when we write new data. | 2347 // when we write the same data, but does set it when we write new data. |
| 2349 TEST_F(SyncManagerTest, SetNonBookmarkTitle) { | 2348 TEST_F(SyncManagerTest, SetNonBookmarkTitle) { |
| 2350 std::string client_tag = "title"; | 2349 std::string client_tag = "title"; |
| 2351 sync_pb::EntitySpecifics entity_specifics; | 2350 sync_pb::EntitySpecifics entity_specifics; |
| 2352 entity_specifics.mutable_preference()->set_name("name"); | 2351 entity_specifics.mutable_preference()->set_name("name"); |
| 2353 entity_specifics.mutable_preference()->set_value("value"); | 2352 entity_specifics.mutable_preference()->set_value("value"); |
| 2354 MakeServerNode(sync_manager_.GetUserShare(), | 2353 MakeServerNode(sync_manager_.GetUserShare(), |
| 2355 syncer::PREFERENCES, | 2354 PREFERENCES, |
| 2356 client_tag, | 2355 client_tag, |
| 2357 BaseNode::GenerateSyncableHash(syncer::PREFERENCES, | 2356 BaseNode::GenerateSyncableHash(PREFERENCES, |
| 2358 client_tag), | 2357 client_tag), |
| 2359 entity_specifics); | 2358 entity_specifics); |
| 2360 // New node shouldn't start off unsynced. | 2359 // New node shouldn't start off unsynced. |
| 2361 EXPECT_FALSE(ResetUnsyncedEntry(syncer::PREFERENCES, client_tag)); | 2360 EXPECT_FALSE(ResetUnsyncedEntry(PREFERENCES, client_tag)); |
| 2362 | 2361 |
| 2363 // Manually change to the same title. Should not set is_unsynced. | 2362 // Manually change to the same title. Should not set is_unsynced. |
| 2364 { | 2363 { |
| 2365 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2364 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2366 WriteNode node(&trans); | 2365 WriteNode node(&trans); |
| 2367 EXPECT_EQ(BaseNode::INIT_OK, | 2366 EXPECT_EQ(BaseNode::INIT_OK, |
| 2368 node.InitByClientTagLookup(syncer::PREFERENCES, client_tag)); | 2367 node.InitByClientTagLookup(PREFERENCES, client_tag)); |
| 2369 node.SetTitle(UTF8ToWide(client_tag)); | 2368 node.SetTitle(UTF8ToWide(client_tag)); |
| 2370 } | 2369 } |
| 2371 EXPECT_FALSE(ResetUnsyncedEntry(syncer::PREFERENCES, client_tag)); | 2370 EXPECT_FALSE(ResetUnsyncedEntry(PREFERENCES, client_tag)); |
| 2372 | 2371 |
| 2373 // Manually change to new title. Should set is_unsynced. | 2372 // Manually change to new title. Should set is_unsynced. |
| 2374 { | 2373 { |
| 2375 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2374 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2376 WriteNode node(&trans); | 2375 WriteNode node(&trans); |
| 2377 EXPECT_EQ(BaseNode::INIT_OK, | 2376 EXPECT_EQ(BaseNode::INIT_OK, |
| 2378 node.InitByClientTagLookup(syncer::PREFERENCES, client_tag)); | 2377 node.InitByClientTagLookup(PREFERENCES, client_tag)); |
| 2379 node.SetTitle(UTF8ToWide("title2")); | 2378 node.SetTitle(UTF8ToWide("title2")); |
| 2380 } | 2379 } |
| 2381 EXPECT_TRUE(ResetUnsyncedEntry(syncer::PREFERENCES, client_tag)); | 2380 EXPECT_TRUE(ResetUnsyncedEntry(PREFERENCES, client_tag)); |
| 2382 } | 2381 } |
| 2383 | 2382 |
| 2384 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted | 2383 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted |
| 2385 // non-bookmarks when we write the same data or when we write new data | 2384 // non-bookmarks when we write the same data or when we write new data |
| 2386 // data (should remained kEncryptedString). | 2385 // data (should remained kEncryptedString). |
| 2387 TEST_F(SyncManagerTest, SetNonBookmarkTitleWithEncryption) { | 2386 TEST_F(SyncManagerTest, SetNonBookmarkTitleWithEncryption) { |
| 2388 std::string client_tag = "title"; | 2387 std::string client_tag = "title"; |
| 2389 sync_pb::EntitySpecifics entity_specifics; | 2388 sync_pb::EntitySpecifics entity_specifics; |
| 2390 entity_specifics.mutable_preference()->set_name("name"); | 2389 entity_specifics.mutable_preference()->set_name("name"); |
| 2391 entity_specifics.mutable_preference()->set_value("value"); | 2390 entity_specifics.mutable_preference()->set_value("value"); |
| 2392 MakeServerNode(sync_manager_.GetUserShare(), | 2391 MakeServerNode(sync_manager_.GetUserShare(), |
| 2393 syncer::PREFERENCES, | 2392 PREFERENCES, |
| 2394 client_tag, | 2393 client_tag, |
| 2395 BaseNode::GenerateSyncableHash(syncer::PREFERENCES, | 2394 BaseNode::GenerateSyncableHash(PREFERENCES, |
| 2396 client_tag), | 2395 client_tag), |
| 2397 entity_specifics); | 2396 entity_specifics); |
| 2398 // New node shouldn't start off unsynced. | 2397 // New node shouldn't start off unsynced. |
| 2399 EXPECT_FALSE(ResetUnsyncedEntry(syncer::PREFERENCES, client_tag)); | 2398 EXPECT_FALSE(ResetUnsyncedEntry(PREFERENCES, client_tag)); |
| 2400 | 2399 |
| 2401 // Encrypt the datatatype, should set is_unsynced. | 2400 // Encrypt the datatatype, should set is_unsynced. |
| 2402 EXPECT_CALL(observer_, | 2401 EXPECT_CALL(observer_, |
| 2403 OnEncryptedTypesChanged( | 2402 OnEncryptedTypesChanged( |
| 2404 HasModelTypes(syncer::ModelTypeSet::All()), true)); | 2403 HasModelTypes(ModelTypeSet::All()), true)); |
| 2405 EXPECT_CALL(observer_, OnEncryptionComplete()); | 2404 EXPECT_CALL(observer_, OnEncryptionComplete()); |
| 2406 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); | 2405 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, FULL_ENCRYPTION)); |
| 2407 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); | 2406 sync_manager_.RefreshNigori(kTestChromeVersion, base::Bind(&DoNothing)); |
| 2408 PumpLoop(); | 2407 PumpLoop(); |
| 2409 EXPECT_TRUE(ResetUnsyncedEntry(syncer::PREFERENCES, client_tag)); | 2408 EXPECT_TRUE(ResetUnsyncedEntry(PREFERENCES, client_tag)); |
| 2410 | 2409 |
| 2411 // Manually change to the same title. Should not set is_unsynced. | 2410 // Manually change to the same title. Should not set is_unsynced. |
| 2412 // NON_UNIQUE_NAME should be kEncryptedString. | 2411 // NON_UNIQUE_NAME should be kEncryptedString. |
| 2413 { | 2412 { |
| 2414 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2413 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2415 WriteNode node(&trans); | 2414 WriteNode node(&trans); |
| 2416 EXPECT_EQ(BaseNode::INIT_OK, | 2415 EXPECT_EQ(BaseNode::INIT_OK, |
| 2417 node.InitByClientTagLookup(syncer::PREFERENCES, client_tag)); | 2416 node.InitByClientTagLookup(PREFERENCES, client_tag)); |
| 2418 node.SetTitle(UTF8ToWide(client_tag)); | 2417 node.SetTitle(UTF8ToWide(client_tag)); |
| 2419 const syncable::Entry* node_entry = node.GetEntry(); | 2418 const syncable::Entry* node_entry = node.GetEntry(); |
| 2420 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2419 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
| 2421 EXPECT_TRUE(specifics.has_encrypted()); | 2420 EXPECT_TRUE(specifics.has_encrypted()); |
| 2422 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2421 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
| 2423 } | 2422 } |
| 2424 EXPECT_FALSE(ResetUnsyncedEntry(syncer::PREFERENCES, client_tag)); | 2423 EXPECT_FALSE(ResetUnsyncedEntry(PREFERENCES, client_tag)); |
| 2425 | 2424 |
| 2426 // Manually change to new title. Should not set is_unsynced because the | 2425 // Manually change to new title. Should not set is_unsynced because the |
| 2427 // NON_UNIQUE_NAME should still be kEncryptedString. | 2426 // NON_UNIQUE_NAME should still be kEncryptedString. |
| 2428 { | 2427 { |
| 2429 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2428 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2430 WriteNode node(&trans); | 2429 WriteNode node(&trans); |
| 2431 EXPECT_EQ(BaseNode::INIT_OK, | 2430 EXPECT_EQ(BaseNode::INIT_OK, |
| 2432 node.InitByClientTagLookup(syncer::PREFERENCES, client_tag)); | 2431 node.InitByClientTagLookup(PREFERENCES, client_tag)); |
| 2433 node.SetTitle(UTF8ToWide("title2")); | 2432 node.SetTitle(UTF8ToWide("title2")); |
| 2434 const syncable::Entry* node_entry = node.GetEntry(); | 2433 const syncable::Entry* node_entry = node.GetEntry(); |
| 2435 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2434 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
| 2436 EXPECT_TRUE(specifics.has_encrypted()); | 2435 EXPECT_TRUE(specifics.has_encrypted()); |
| 2437 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2436 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
| 2438 EXPECT_FALSE(node_entry->Get(IS_UNSYNCED)); | 2437 EXPECT_FALSE(node_entry->Get(IS_UNSYNCED)); |
| 2439 } | 2438 } |
| 2440 } | 2439 } |
| 2441 | 2440 |
| 2442 // Create an encrypted entry when the cryptographer doesn't think the type is | 2441 // Create an encrypted entry when the cryptographer doesn't think the type is |
| 2443 // marked for encryption. Ensure reads/writes don't break and don't unencrypt | 2442 // marked for encryption. Ensure reads/writes don't break and don't unencrypt |
| 2444 // the data. | 2443 // the data. |
| 2445 TEST_F(SyncManagerTest, SetPreviouslyEncryptedSpecifics) { | 2444 TEST_F(SyncManagerTest, SetPreviouslyEncryptedSpecifics) { |
| 2446 std::string client_tag = "tag"; | 2445 std::string client_tag = "tag"; |
| 2447 std::string url = "url"; | 2446 std::string url = "url"; |
| 2448 std::string url2 = "new_url"; | 2447 std::string url2 = "new_url"; |
| 2449 std::string title = "title"; | 2448 std::string title = "title"; |
| 2450 sync_pb::EntitySpecifics entity_specifics; | 2449 sync_pb::EntitySpecifics entity_specifics; |
| 2451 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2450 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2452 { | 2451 { |
| 2453 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2452 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2454 syncer::Cryptographer* crypto = trans.GetCryptographer(); | 2453 Cryptographer* crypto = trans.GetCryptographer(); |
| 2455 sync_pb::EntitySpecifics bm_specifics; | 2454 sync_pb::EntitySpecifics bm_specifics; |
| 2456 bm_specifics.mutable_bookmark()->set_title("title"); | 2455 bm_specifics.mutable_bookmark()->set_title("title"); |
| 2457 bm_specifics.mutable_bookmark()->set_url("url"); | 2456 bm_specifics.mutable_bookmark()->set_url("url"); |
| 2458 sync_pb::EncryptedData encrypted; | 2457 sync_pb::EncryptedData encrypted; |
| 2459 crypto->Encrypt(bm_specifics, &encrypted); | 2458 crypto->Encrypt(bm_specifics, &encrypted); |
| 2460 entity_specifics.mutable_encrypted()->CopyFrom(encrypted); | 2459 entity_specifics.mutable_encrypted()->CopyFrom(encrypted); |
| 2461 syncer::AddDefaultFieldValue(syncer::BOOKMARKS, &entity_specifics); | 2460 AddDefaultFieldValue(BOOKMARKS, &entity_specifics); |
| 2462 } | 2461 } |
| 2463 MakeServerNode(sync_manager_.GetUserShare(), syncer::BOOKMARKS, client_tag, | 2462 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, |
| 2464 BaseNode::GenerateSyncableHash(syncer::BOOKMARKS, | 2463 BaseNode::GenerateSyncableHash(BOOKMARKS, |
| 2465 client_tag), | 2464 client_tag), |
| 2466 entity_specifics); | 2465 entity_specifics); |
| 2467 | 2466 |
| 2468 { | 2467 { |
| 2469 // Verify the data. | 2468 // Verify the data. |
| 2470 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2469 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2471 ReadNode node(&trans); | 2470 ReadNode node(&trans); |
| 2472 EXPECT_EQ(BaseNode::INIT_OK, | 2471 EXPECT_EQ(BaseNode::INIT_OK, |
| 2473 node.InitByClientTagLookup(syncer::BOOKMARKS, client_tag)); | 2472 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 2474 EXPECT_EQ(title, node.GetTitle()); | 2473 EXPECT_EQ(title, node.GetTitle()); |
| 2475 EXPECT_EQ(GURL(url), node.GetURL()); | 2474 EXPECT_EQ(GURL(url), node.GetURL()); |
| 2476 } | 2475 } |
| 2477 | 2476 |
| 2478 { | 2477 { |
| 2479 // Overwrite the url (which overwrites the specifics). | 2478 // Overwrite the url (which overwrites the specifics). |
| 2480 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2479 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2481 WriteNode node(&trans); | 2480 WriteNode node(&trans); |
| 2482 EXPECT_EQ(BaseNode::INIT_OK, | 2481 EXPECT_EQ(BaseNode::INIT_OK, |
| 2483 node.InitByClientTagLookup(syncer::BOOKMARKS, client_tag)); | 2482 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 2484 node.SetURL(GURL(url2)); | 2483 node.SetURL(GURL(url2)); |
| 2485 } | 2484 } |
| 2486 | 2485 |
| 2487 { | 2486 { |
| 2488 // Verify it's still encrypted and it has the most recent url. | 2487 // Verify it's still encrypted and it has the most recent url. |
| 2489 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2488 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2490 ReadNode node(&trans); | 2489 ReadNode node(&trans); |
| 2491 EXPECT_EQ(BaseNode::INIT_OK, | 2490 EXPECT_EQ(BaseNode::INIT_OK, |
| 2492 node.InitByClientTagLookup(syncer::BOOKMARKS, client_tag)); | 2491 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 2493 EXPECT_EQ(title, node.GetTitle()); | 2492 EXPECT_EQ(title, node.GetTitle()); |
| 2494 EXPECT_EQ(GURL(url2), node.GetURL()); | 2493 EXPECT_EQ(GURL(url2), node.GetURL()); |
| 2495 const syncable::Entry* node_entry = node.GetEntry(); | 2494 const syncable::Entry* node_entry = node.GetEntry(); |
| 2496 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2495 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
| 2497 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2496 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
| 2498 EXPECT_TRUE(specifics.has_encrypted()); | 2497 EXPECT_TRUE(specifics.has_encrypted()); |
| 2499 } | 2498 } |
| 2500 } | 2499 } |
| 2501 | 2500 |
| 2502 class MockSyncScheduler : public FakeSyncScheduler { | 2501 class MockSyncScheduler : public FakeSyncScheduler { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2531 scheduler_ = new MockSyncScheduler(); | 2530 scheduler_ = new MockSyncScheduler(); |
| 2532 return new ComponentsFactory(scheduler_); | 2531 return new ComponentsFactory(scheduler_); |
| 2533 } | 2532 } |
| 2534 MockSyncScheduler* scheduler_; | 2533 MockSyncScheduler* scheduler_; |
| 2535 }; | 2534 }; |
| 2536 | 2535 |
| 2537 // Test that the configuration params are properly created and sent to | 2536 // Test that the configuration params are properly created and sent to |
| 2538 // ScheduleConfigure. No callback should be invoked. | 2537 // ScheduleConfigure. No callback should be invoked. |
| 2539 TEST_F(SyncManagerTestWithMockScheduler, BasicConfiguration) { | 2538 TEST_F(SyncManagerTestWithMockScheduler, BasicConfiguration) { |
| 2540 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; | 2539 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; |
| 2541 syncer::ModelTypeSet types_to_download(syncer::BOOKMARKS, | 2540 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES); |
| 2542 syncer::PREFERENCES); | 2541 ModelSafeRoutingInfo new_routing_info; |
| 2543 syncer::ModelSafeRoutingInfo new_routing_info; | |
| 2544 GetModelSafeRoutingInfo(&new_routing_info); | 2542 GetModelSafeRoutingInfo(&new_routing_info); |
| 2545 | 2543 |
| 2546 ConfigurationParams params; | 2544 ConfigurationParams params; |
| 2547 EXPECT_CALL(*scheduler_, Start(SyncScheduler::CONFIGURATION_MODE)); | 2545 EXPECT_CALL(*scheduler_, Start(SyncScheduler::CONFIGURATION_MODE)); |
| 2548 EXPECT_CALL(*scheduler_, ScheduleConfiguration(_)). | 2546 EXPECT_CALL(*scheduler_, ScheduleConfiguration(_)). |
| 2549 WillOnce(DoAll(SaveArg<0>(¶ms), Return(true))); | 2547 WillOnce(DoAll(SaveArg<0>(¶ms), Return(true))); |
| 2550 | 2548 |
| 2551 CallbackCounter ready_task_counter, retry_task_counter; | 2549 CallbackCounter ready_task_counter, retry_task_counter; |
| 2552 sync_manager_.ConfigureSyncer( | 2550 sync_manager_.ConfigureSyncer( |
| 2553 reason, | 2551 reason, |
| 2554 types_to_download, | 2552 types_to_download, |
| 2555 new_routing_info, | 2553 new_routing_info, |
| 2556 base::Bind(&CallbackCounter::Callback, | 2554 base::Bind(&CallbackCounter::Callback, |
| 2557 base::Unretained(&ready_task_counter)), | 2555 base::Unretained(&ready_task_counter)), |
| 2558 base::Bind(&CallbackCounter::Callback, | 2556 base::Bind(&CallbackCounter::Callback, |
| 2559 base::Unretained(&retry_task_counter))); | 2557 base::Unretained(&retry_task_counter))); |
| 2560 EXPECT_EQ(0, ready_task_counter.times_called()); | 2558 EXPECT_EQ(0, ready_task_counter.times_called()); |
| 2561 EXPECT_EQ(0, retry_task_counter.times_called()); | 2559 EXPECT_EQ(0, retry_task_counter.times_called()); |
| 2562 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, | 2560 EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::RECONFIGURATION, |
| 2563 params.source); | 2561 params.source); |
| 2564 EXPECT_TRUE(types_to_download.Equals(params.types_to_download)); | 2562 EXPECT_TRUE(types_to_download.Equals(params.types_to_download)); |
| 2565 EXPECT_EQ(new_routing_info, params.routing_info); | 2563 EXPECT_EQ(new_routing_info, params.routing_info); |
| 2566 } | 2564 } |
| 2567 | 2565 |
| 2568 // Test that the retry callback is invoked on configuration failure. | 2566 // Test that the retry callback is invoked on configuration failure. |
| 2569 TEST_F(SyncManagerTestWithMockScheduler, ConfigurationRetry) { | 2567 TEST_F(SyncManagerTestWithMockScheduler, ConfigurationRetry) { |
| 2570 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; | 2568 ConfigureReason reason = CONFIGURE_REASON_RECONFIGURATION; |
| 2571 syncer::ModelTypeSet types_to_download(syncer::BOOKMARKS, | 2569 ModelTypeSet types_to_download(BOOKMARKS, PREFERENCES); |
| 2572 syncer::PREFERENCES); | 2570 ModelSafeRoutingInfo new_routing_info; |
| 2573 syncer::ModelSafeRoutingInfo new_routing_info; | |
| 2574 GetModelSafeRoutingInfo(&new_routing_info); | 2571 GetModelSafeRoutingInfo(&new_routing_info); |
| 2575 | 2572 |
| 2576 ConfigurationParams params; | 2573 ConfigurationParams params; |
| 2577 EXPECT_CALL(*scheduler_, Start(SyncScheduler::CONFIGURATION_MODE)); | 2574 EXPECT_CALL(*scheduler_, Start(SyncScheduler::CONFIGURATION_MODE)); |
| 2578 EXPECT_CALL(*scheduler_, ScheduleConfiguration(_)). | 2575 EXPECT_CALL(*scheduler_, ScheduleConfiguration(_)). |
| 2579 WillOnce(DoAll(SaveArg<0>(¶ms), Return(false))); | 2576 WillOnce(DoAll(SaveArg<0>(¶ms), Return(false))); |
| 2580 | 2577 |
| 2581 CallbackCounter ready_task_counter, retry_task_counter; | 2578 CallbackCounter ready_task_counter, retry_task_counter; |
| 2582 sync_manager_.ConfigureSyncer( | 2579 sync_manager_.ConfigureSyncer( |
| 2583 reason, | 2580 reason, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2631 // Ensure only bookmarks and nigori lost their progress marker. Preferences | 2628 // Ensure only bookmarks and nigori lost their progress marker. Preferences |
| 2632 // should still have it. | 2629 // should still have it. |
| 2633 partial_types = | 2630 partial_types = |
| 2634 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()); | 2631 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()); |
| 2635 EXPECT_TRUE(partial_types.Has(NIGORI)); | 2632 EXPECT_TRUE(partial_types.Has(NIGORI)); |
| 2636 EXPECT_TRUE(partial_types.Has(BOOKMARKS)); | 2633 EXPECT_TRUE(partial_types.Has(BOOKMARKS)); |
| 2637 EXPECT_FALSE(partial_types.Has(PREFERENCES)); | 2634 EXPECT_FALSE(partial_types.Has(PREFERENCES)); |
| 2638 } | 2635 } |
| 2639 | 2636 |
| 2640 } // namespace | 2637 } // namespace |
| OLD | NEW |