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