| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 #include "sync/protocol/preference_specifics.pb.h" | 56 #include "sync/protocol/preference_specifics.pb.h" |
| 57 #include "sync/protocol/proto_value_conversions.h" | 57 #include "sync/protocol/proto_value_conversions.h" |
| 58 #include "sync/protocol/sync.pb.h" | 58 #include "sync/protocol/sync.pb.h" |
| 59 #include "sync/sessions/sync_session.h" | 59 #include "sync/sessions/sync_session.h" |
| 60 #include "sync/syncable/directory.h" | 60 #include "sync/syncable/directory.h" |
| 61 #include "sync/syncable/entry.h" | 61 #include "sync/syncable/entry.h" |
| 62 #include "sync/syncable/mutable_entry.h" | 62 #include "sync/syncable/mutable_entry.h" |
| 63 #include "sync/syncable/nigori_util.h" | 63 #include "sync/syncable/nigori_util.h" |
| 64 #include "sync/syncable/read_transaction.h" | 64 #include "sync/syncable/read_transaction.h" |
| 65 #include "sync/syncable/syncable_id.h" | 65 #include "sync/syncable/syncable_id.h" |
| 66 #include "sync/syncable/syncable_util.h" |
| 66 #include "sync/syncable/write_transaction.h" | 67 #include "sync/syncable/write_transaction.h" |
| 67 #include "sync/test/callback_counter.h" | 68 #include "sync/test/callback_counter.h" |
| 68 #include "sync/test/engine/fake_sync_scheduler.h" | 69 #include "sync/test/engine/fake_sync_scheduler.h" |
| 69 #include "sync/test/fake_encryptor.h" | 70 #include "sync/test/fake_encryptor.h" |
| 70 #include "sync/test/fake_extensions_activity_monitor.h" | 71 #include "sync/test/fake_extensions_activity_monitor.h" |
| 71 #include "sync/util/cryptographer.h" | 72 #include "sync/util/cryptographer.h" |
| 72 #include "sync/util/extensions_activity_monitor.h" | 73 #include "sync/util/extensions_activity_monitor.h" |
| 73 #include "sync/util/test_unrecoverable_error_handler.h" | 74 #include "sync/util/test_unrecoverable_error_handler.h" |
| 74 #include "sync/util/time.h" | 75 #include "sync/util/time.h" |
| 75 #include "testing/gmock/include/gmock/gmock.h" | 76 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 // newly-created node. | 118 // newly-created node. |
| 118 int64 MakeNode(UserShare* share, | 119 int64 MakeNode(UserShare* share, |
| 119 ModelType model_type, | 120 ModelType model_type, |
| 120 const std::string& client_tag) { | 121 const std::string& client_tag) { |
| 121 WriteTransaction trans(FROM_HERE, share); | 122 WriteTransaction trans(FROM_HERE, share); |
| 122 ReadNode root_node(&trans); | 123 ReadNode root_node(&trans); |
| 123 root_node.InitByRootLookup(); | 124 root_node.InitByRootLookup(); |
| 124 WriteNode node(&trans); | 125 WriteNode node(&trans); |
| 125 WriteNode::InitUniqueByCreationResult result = | 126 WriteNode::InitUniqueByCreationResult result = |
| 126 node.InitUniqueByCreation(model_type, root_node, client_tag); | 127 node.InitUniqueByCreation(model_type, root_node, client_tag); |
| 127 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); | 128 DCHECK_EQ(WriteNode::INIT_SUCCESS, result); |
| 128 node.SetIsFolder(false); | 129 node.SetIsFolder(false); |
| 129 return node.GetId(); | 130 return node.GetId(); |
| 130 } | 131 } |
| 131 | 132 |
| 132 // Makes a non-folder child of a non-root node. Returns the id of the | 133 // Makes a non-folder child of a non-root node. Returns the id of the |
| 133 // newly-created node. | 134 // newly-created node. |
| 134 int64 MakeNodeWithParent(UserShare* share, | 135 int64 MakeNodeWithParent(UserShare* share, |
| 135 ModelType model_type, | 136 ModelType model_type, |
| 136 const std::string& client_tag, | |
| 137 int64 parent_id) { | 137 int64 parent_id) { |
| 138 DCHECK_EQ(model_type, BOOKMARKS); // Only bookmarks have hierarchy. |
| 138 WriteTransaction trans(FROM_HERE, share); | 139 WriteTransaction trans(FROM_HERE, share); |
| 139 ReadNode parent_node(&trans); | 140 ReadNode parent_node(&trans); |
| 140 EXPECT_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id)); | 141 DCHECK_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id)); |
| 141 WriteNode node(&trans); | 142 WriteNode node(&trans); |
| 142 WriteNode::InitUniqueByCreationResult result = | 143 DCHECK(node.InitBookmarkByCreation(parent_node, NULL)); |
| 143 node.InitUniqueByCreation(model_type, parent_node, client_tag); | |
| 144 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); | |
| 145 node.SetIsFolder(false); | 144 node.SetIsFolder(false); |
| 146 return node.GetId(); | 145 return node.GetId(); |
| 147 } | 146 } |
| 148 | 147 |
| 149 // Makes a folder child of a non-root node. Returns the id of the | 148 // Makes a folder child of a non-root node. Returns the id of the |
| 150 // newly-created node. | 149 // newly-created node. |
| 151 int64 MakeFolderWithParent(UserShare* share, | 150 int64 MakeFolderWithParent(UserShare* share, |
| 152 ModelType model_type, | 151 ModelType model_type, |
| 153 int64 parent_id, | 152 int64 parent_id, |
| 154 BaseNode* predecessor) { | 153 BaseNode* predecessor) { |
| 155 WriteTransaction trans(FROM_HERE, share); | 154 WriteTransaction trans(FROM_HERE, share); |
| 156 ReadNode parent_node(&trans); | 155 ReadNode parent_node(&trans); |
| 157 EXPECT_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id)); | 156 DCHECK_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id)); |
| 158 WriteNode node(&trans); | 157 WriteNode node(&trans); |
| 159 EXPECT_TRUE(node.InitByCreation(model_type, parent_node, predecessor)); | 158 DCHECK(node.InitBookmarkByCreation(parent_node, predecessor)); |
| 160 node.SetIsFolder(true); | 159 node.SetIsFolder(true); |
| 161 return node.GetId(); | 160 return node.GetId(); |
| 162 } | 161 } |
| 163 | 162 |
| 163 int64 MakeBookmarkWithParent(UserShare* share, |
| 164 int64 parent_id, |
| 165 BaseNode* predecessor) { |
| 166 WriteTransaction trans(FROM_HERE, share); |
| 167 ReadNode parent_node(&trans); |
| 168 DCHECK_EQ(BaseNode::INIT_OK, parent_node.InitByIdLookup(parent_id)); |
| 169 WriteNode node(&trans); |
| 170 DCHECK(node.InitBookmarkByCreation(parent_node, predecessor)); |
| 171 return node.GetId(); |
| 172 } |
| 173 |
| 164 // Creates the "synced" root node for a particular datatype. We use the syncable | 174 // Creates the "synced" root node for a particular datatype. We use the syncable |
| 165 // methods here so that the syncer treats these nodes as if they were already | 175 // methods here so that the syncer treats these nodes as if they were already |
| 166 // received from the server. | 176 // received from the server. |
| 167 int64 MakeServerNodeForType(UserShare* share, | 177 int64 MakeServerNodeForType(UserShare* share, |
| 168 ModelType model_type) { | 178 ModelType model_type) { |
| 169 sync_pb::EntitySpecifics specifics; | 179 sync_pb::EntitySpecifics specifics; |
| 170 AddDefaultFieldValue(model_type, &specifics); | 180 AddDefaultFieldValue(model_type, &specifics); |
| 171 syncable::WriteTransaction trans( | 181 syncable::WriteTransaction trans( |
| 172 FROM_HERE, syncable::UNITTEST, share->directory.get()); | 182 FROM_HERE, syncable::UNITTEST, share->directory.get()); |
| 173 // Attempt to lookup by nigori tag. | 183 // Attempt to lookup by nigori tag. |
| 174 std::string type_tag = ModelTypeToRootTag(model_type); | 184 std::string type_tag = ModelTypeToRootTag(model_type); |
| 175 syncable::Id node_id = syncable::Id::CreateFromServerId(type_tag); | 185 syncable::Id node_id = syncable::Id::CreateFromServerId(type_tag); |
| 176 syncable::MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, | 186 syncable::MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, |
| 177 node_id); | 187 node_id); |
| 178 EXPECT_TRUE(entry.good()); | 188 EXPECT_TRUE(entry.good()); |
| 179 entry.Put(syncable::BASE_VERSION, 1); | 189 entry.Put(syncable::BASE_VERSION, 1); |
| 180 entry.Put(syncable::SERVER_VERSION, 1); | 190 entry.Put(syncable::SERVER_VERSION, 1); |
| 181 entry.Put(syncable::IS_UNAPPLIED_UPDATE, false); | 191 entry.Put(syncable::IS_UNAPPLIED_UPDATE, false); |
| 182 entry.Put(syncable::SERVER_PARENT_ID, syncable::GetNullId()); | 192 entry.Put(syncable::SERVER_PARENT_ID, syncable::GetNullId()); |
| 183 entry.Put(syncable::SERVER_IS_DIR, true); | 193 entry.Put(syncable::SERVER_IS_DIR, true); |
| 184 entry.Put(syncable::IS_DIR, true); | 194 entry.Put(syncable::IS_DIR, true); |
| 185 entry.Put(syncable::SERVER_SPECIFICS, specifics); | 195 entry.Put(syncable::SERVER_SPECIFICS, specifics); |
| 186 entry.Put(syncable::UNIQUE_SERVER_TAG, type_tag); | 196 entry.Put(syncable::UNIQUE_SERVER_TAG, type_tag); |
| 187 entry.Put(syncable::NON_UNIQUE_NAME, type_tag); | 197 entry.Put(syncable::NON_UNIQUE_NAME, type_tag); |
| 188 entry.Put(syncable::IS_DEL, false); | 198 entry.Put(syncable::IS_DEL, false); |
| 189 entry.Put(syncable::SPECIFICS, specifics); | 199 entry.Put(syncable::SPECIFICS, specifics); |
| 190 return entry.Get(syncable::META_HANDLE); | 200 return entry.Get(syncable::META_HANDLE); |
| 191 } | 201 } |
| 192 | 202 |
| 203 int64 GetServerNodeForType(UserShare* share, ModelType type) { |
| 204 ReadTransaction trans(FROM_HERE, share); |
| 205 ReadNode bookmark_root(&trans); |
| 206 EXPECT_EQ(BaseNode::INIT_OK, |
| 207 bookmark_root.InitByTagLookup(ModelTypeToRootTag(BOOKMARKS))); |
| 208 return bookmark_root.GetId(); |
| 209 } |
| 210 |
| 193 // Simulates creating a "synced" node as a child of the root datatype node. | 211 // Simulates creating a "synced" node as a child of the root datatype node. |
| 194 int64 MakeServerNode(UserShare* share, ModelType model_type, | 212 int64 MakeServerNode(UserShare* share, ModelType model_type, |
| 195 const std::string& client_tag, | 213 const std::string& client_tag, |
| 196 const std::string& hashed_tag, | 214 const std::string& hashed_tag, |
| 197 const sync_pb::EntitySpecifics& specifics) { | 215 const sync_pb::EntitySpecifics& specifics) { |
| 198 syncable::WriteTransaction trans( | 216 syncable::WriteTransaction trans( |
| 199 FROM_HERE, syncable::UNITTEST, share->directory.get()); | 217 FROM_HERE, syncable::UNITTEST, share->directory.get()); |
| 200 syncable::Entry root_entry(&trans, syncable::GET_BY_SERVER_TAG, | 218 syncable::Entry root_entry(&trans, syncable::GET_BY_SERVER_TAG, |
| 201 ModelTypeToRootTag(model_type)); | 219 ModelTypeToRootTag(model_type)); |
| 202 EXPECT_TRUE(root_entry.good()); | 220 EXPECT_TRUE(root_entry.good()); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 275 |
| 258 TEST_F(SyncApiTest, BasicTagWrite) { | 276 TEST_F(SyncApiTest, BasicTagWrite) { |
| 259 { | 277 { |
| 260 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 278 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 261 ReadNode root_node(&trans); | 279 ReadNode root_node(&trans); |
| 262 root_node.InitByRootLookup(); | 280 root_node.InitByRootLookup(); |
| 263 EXPECT_EQ(root_node.GetFirstChildId(), 0); | 281 EXPECT_EQ(root_node.GetFirstChildId(), 0); |
| 264 } | 282 } |
| 265 | 283 |
| 266 ignore_result(MakeNode(test_user_share_.user_share(), | 284 ignore_result(MakeNode(test_user_share_.user_share(), |
| 267 BOOKMARKS, "testtag")); | 285 AUTOFILL, "testtag")); |
| 268 | 286 |
| 269 { | 287 { |
| 270 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 288 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 271 ReadNode node(&trans); | 289 ReadNode node(&trans); |
| 272 EXPECT_EQ(BaseNode::INIT_OK, | 290 EXPECT_EQ(BaseNode::INIT_OK, |
| 273 node.InitByClientTagLookup(BOOKMARKS, "testtag")); | 291 node.InitByClientTagLookup(AUTOFILL, "testtag")); |
| 274 | 292 |
| 275 ReadNode root_node(&trans); | 293 ReadNode root_node(&trans); |
| 276 root_node.InitByRootLookup(); | 294 root_node.InitByRootLookup(); |
| 277 EXPECT_NE(node.GetId(), 0); | 295 EXPECT_NE(node.GetId(), 0); |
| 278 EXPECT_EQ(node.GetId(), root_node.GetFirstChildId()); | 296 EXPECT_EQ(node.GetId(), root_node.GetFirstChildId()); |
| 279 } | 297 } |
| 280 } | 298 } |
| 281 | 299 |
| 282 TEST_F(SyncApiTest, GenerateSyncableHash) { | 300 TEST_F(SyncApiTest, GenerateSyncableHash) { |
| 283 EXPECT_EQ("OyaXV5mEzrPS4wbogmtKvRfekAI=", | 301 EXPECT_EQ("TrJxl8908A2qDbaLzjxjyUzskpY=", |
| 284 BaseNode::GenerateSyncableHash(BOOKMARKS, "tag1")); | 302 syncable::GenerateSyncableHash(THEMES, "tag1")); |
| 285 EXPECT_EQ("iNFQtRFQb+IZcn1kKUJEZDDkLs4=", | 303 EXPECT_EQ("iNFQtRFQb+IZcn1kKUJEZDDkLs4=", |
| 286 BaseNode::GenerateSyncableHash(PREFERENCES, "tag1")); | 304 syncable::GenerateSyncableHash(PREFERENCES, "tag1")); |
| 287 EXPECT_EQ("gO1cPZQXaM73sHOvSA+tKCKFs58=", | 305 EXPECT_EQ("gO1cPZQXaM73sHOvSA+tKCKFs58=", |
| 288 BaseNode::GenerateSyncableHash(AUTOFILL, "tag1")); | 306 syncable::GenerateSyncableHash(AUTOFILL, "tag1")); |
| 289 | 307 |
| 290 EXPECT_EQ("A0eYIHXM1/jVwKDDp12Up20IkKY=", | 308 EXPECT_EQ("YCbRusldaxqFnrd36Y7cJagN8TA=", |
| 291 BaseNode::GenerateSyncableHash(BOOKMARKS, "tag2")); | 309 syncable::GenerateSyncableHash(THEMES, "tag2")); |
| 292 EXPECT_EQ("XYxkF7bhS4eItStFgiOIAU23swI=", | 310 EXPECT_EQ("XYxkF7bhS4eItStFgiOIAU23swI=", |
| 293 BaseNode::GenerateSyncableHash(PREFERENCES, "tag2")); | 311 syncable::GenerateSyncableHash(PREFERENCES, "tag2")); |
| 294 EXPECT_EQ("GFiWzo5NGhjLlN+OyCfhy28DJTQ=", | 312 EXPECT_EQ("GFiWzo5NGhjLlN+OyCfhy28DJTQ=", |
| 295 BaseNode::GenerateSyncableHash(AUTOFILL, "tag2")); | 313 syncable::GenerateSyncableHash(AUTOFILL, "tag2")); |
| 296 } | 314 } |
| 297 | 315 |
| 298 TEST_F(SyncApiTest, ModelTypesSiloed) { | 316 TEST_F(SyncApiTest, ModelTypesSiloed) { |
| 299 { | 317 { |
| 300 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 318 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 301 ReadNode root_node(&trans); | 319 ReadNode root_node(&trans); |
| 302 root_node.InitByRootLookup(); | 320 root_node.InitByRootLookup(); |
| 303 EXPECT_EQ(root_node.GetFirstChildId(), 0); | 321 EXPECT_EQ(root_node.GetFirstChildId(), 0); |
| 304 } | 322 } |
| 305 | 323 |
| 306 ignore_result(MakeNode(test_user_share_.user_share(), | 324 ignore_result(MakeNode(test_user_share_.user_share(), |
| 307 BOOKMARKS, "collideme")); | 325 THEMES, "collideme")); |
| 308 ignore_result(MakeNode(test_user_share_.user_share(), | 326 ignore_result(MakeNode(test_user_share_.user_share(), |
| 309 PREFERENCES, "collideme")); | 327 PREFERENCES, "collideme")); |
| 310 ignore_result(MakeNode(test_user_share_.user_share(), | 328 ignore_result(MakeNode(test_user_share_.user_share(), |
| 311 AUTOFILL, "collideme")); | 329 AUTOFILL, "collideme")); |
| 312 | 330 |
| 313 { | 331 { |
| 314 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 332 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 315 | 333 |
| 316 ReadNode bookmarknode(&trans); | 334 ReadNode bookmarknode(&trans); |
| 317 EXPECT_EQ(BaseNode::INIT_OK, | 335 EXPECT_EQ(BaseNode::INIT_OK, |
| 318 bookmarknode.InitByClientTagLookup(BOOKMARKS, | 336 bookmarknode.InitByClientTagLookup(THEMES, |
| 319 "collideme")); | 337 "collideme")); |
| 320 | 338 |
| 321 ReadNode prefnode(&trans); | 339 ReadNode prefnode(&trans); |
| 322 EXPECT_EQ(BaseNode::INIT_OK, | 340 EXPECT_EQ(BaseNode::INIT_OK, |
| 323 prefnode.InitByClientTagLookup(PREFERENCES, | 341 prefnode.InitByClientTagLookup(PREFERENCES, |
| 324 "collideme")); | 342 "collideme")); |
| 325 | 343 |
| 326 ReadNode autofillnode(&trans); | 344 ReadNode autofillnode(&trans); |
| 327 EXPECT_EQ(BaseNode::INIT_OK, | 345 EXPECT_EQ(BaseNode::INIT_OK, |
| 328 autofillnode.InitByClientTagLookup(AUTOFILL, | 346 autofillnode.InitByClientTagLookup(AUTOFILL, |
| 329 "collideme")); | 347 "collideme")); |
| 330 | 348 |
| 331 EXPECT_NE(bookmarknode.GetId(), prefnode.GetId()); | 349 EXPECT_NE(bookmarknode.GetId(), prefnode.GetId()); |
| 332 EXPECT_NE(autofillnode.GetId(), prefnode.GetId()); | 350 EXPECT_NE(autofillnode.GetId(), prefnode.GetId()); |
| 333 EXPECT_NE(bookmarknode.GetId(), autofillnode.GetId()); | 351 EXPECT_NE(bookmarknode.GetId(), autofillnode.GetId()); |
| 334 } | 352 } |
| 335 } | 353 } |
| 336 | 354 |
| 337 TEST_F(SyncApiTest, ReadMissingTagsFails) { | 355 TEST_F(SyncApiTest, ReadMissingTagsFails) { |
| 338 { | 356 { |
| 339 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 357 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 340 ReadNode node(&trans); | 358 ReadNode node(&trans); |
| 341 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, | 359 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, |
| 342 node.InitByClientTagLookup(BOOKMARKS, | 360 node.InitByClientTagLookup(THEMES, |
| 343 "testtag")); | 361 "testtag")); |
| 344 } | 362 } |
| 345 { | 363 { |
| 346 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 364 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 347 WriteNode node(&trans); | 365 WriteNode node(&trans); |
| 348 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, | 366 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_NOT_GOOD, |
| 349 node.InitByClientTagLookup(BOOKMARKS, | 367 node.InitByClientTagLookup(THEMES, |
| 350 "testtag")); | 368 "testtag")); |
| 351 } | 369 } |
| 352 } | 370 } |
| 353 | 371 |
| 354 // TODO(chron): Hook this all up to the server and write full integration tests | 372 // TODO(chron): Hook this all up to the server and write full integration tests |
| 355 // for update->undelete behavior. | 373 // for update->undelete behavior. |
| 356 TEST_F(SyncApiTest, TestDeleteBehavior) { | 374 TEST_F(SyncApiTest, TestDeleteBehavior) { |
| 357 int64 node_id; | 375 int64 node_id; |
| 358 int64 folder_id; | 376 int64 folder_id; |
| 359 std::string test_title("test1"); | 377 std::string test_title("test1"); |
| 360 | 378 |
| 361 { | 379 { |
| 362 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 380 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 363 ReadNode root_node(&trans); | 381 ReadNode root_node(&trans); |
| 364 root_node.InitByRootLookup(); | 382 root_node.InitByRootLookup(); |
| 365 | 383 |
| 366 // we'll use this spare folder later | 384 // we'll use this spare folder later |
| 367 WriteNode folder_node(&trans); | 385 WriteNode folder_node(&trans); |
| 368 EXPECT_TRUE(folder_node.InitByCreation(BOOKMARKS, | 386 EXPECT_TRUE(folder_node.InitBookmarkByCreation(root_node, NULL)); |
| 369 root_node, NULL)); | |
| 370 folder_id = folder_node.GetId(); | 387 folder_id = folder_node.GetId(); |
| 371 | 388 |
| 372 WriteNode wnode(&trans); | 389 WriteNode wnode(&trans); |
| 373 WriteNode::InitUniqueByCreationResult result = | 390 WriteNode::InitUniqueByCreationResult result = |
| 374 wnode.InitUniqueByCreation(BOOKMARKS, root_node, "testtag"); | 391 wnode.InitUniqueByCreation(AUTOFILL, root_node, "testtag"); |
| 375 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); | 392 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 376 wnode.SetIsFolder(false); | 393 wnode.SetIsFolder(false); |
| 377 wnode.SetTitle(UTF8ToWide(test_title)); | 394 wnode.SetTitle(UTF8ToWide(test_title)); |
| 378 | 395 |
| 379 node_id = wnode.GetId(); | 396 node_id = wnode.GetId(); |
| 380 } | 397 } |
| 381 | 398 |
| 382 // Ensure we can delete something with a tag. | 399 // Ensure we can delete something with a tag. |
| 383 { | 400 { |
| 384 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 401 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 385 WriteNode wnode(&trans); | 402 WriteNode wnode(&trans); |
| 386 EXPECT_EQ(BaseNode::INIT_OK, | 403 EXPECT_EQ(BaseNode::INIT_OK, |
| 387 wnode.InitByClientTagLookup(BOOKMARKS, | 404 wnode.InitByClientTagLookup(AUTOFILL, "testtag")); |
| 388 "testtag")); | |
| 389 EXPECT_FALSE(wnode.GetIsFolder()); | 405 EXPECT_FALSE(wnode.GetIsFolder()); |
| 390 EXPECT_EQ(wnode.GetTitle(), test_title); | 406 EXPECT_EQ(wnode.GetTitle(), test_title); |
| 391 | 407 |
| 392 wnode.Remove(); | 408 wnode.Remove(); |
| 393 } | 409 } |
| 394 | 410 |
| 395 // Lookup of a node which was deleted should return failure, | 411 // Lookup of a node which was deleted should return failure, |
| 396 // but have found some data about the node. | 412 // but have found some data about the node. |
| 397 { | 413 { |
| 398 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 414 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 399 ReadNode node(&trans); | 415 ReadNode node(&trans); |
| 400 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL, | 416 EXPECT_EQ(BaseNode::INIT_FAILED_ENTRY_IS_DEL, |
| 401 node.InitByClientTagLookup(BOOKMARKS, | 417 node.InitByClientTagLookup(AUTOFILL, "testtag")); |
| 402 "testtag")); | |
| 403 // Note that for proper function of this API this doesn't need to be | 418 // Note that for proper function of this API this doesn't need to be |
| 404 // filled, we're checking just to make sure the DB worked in this test. | 419 // filled, we're checking just to make sure the DB worked in this test. |
| 405 EXPECT_EQ(node.GetTitle(), test_title); | 420 EXPECT_EQ(node.GetTitle(), test_title); |
| 406 } | 421 } |
| 407 | 422 |
| 408 { | 423 { |
| 409 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 424 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 410 ReadNode folder_node(&trans); | 425 ReadNode folder_node(&trans); |
| 411 EXPECT_EQ(BaseNode::INIT_OK, folder_node.InitByIdLookup(folder_id)); | 426 EXPECT_EQ(BaseNode::INIT_OK, folder_node.InitByIdLookup(folder_id)); |
| 412 | 427 |
| 413 WriteNode wnode(&trans); | 428 WriteNode wnode(&trans); |
| 414 // This will undelete the tag. | 429 // This will undelete the tag. |
| 415 WriteNode::InitUniqueByCreationResult result = | 430 WriteNode::InitUniqueByCreationResult result = |
| 416 wnode.InitUniqueByCreation(BOOKMARKS, folder_node, "testtag"); | 431 wnode.InitUniqueByCreation(AUTOFILL, folder_node, "testtag"); |
| 417 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); | 432 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 418 EXPECT_EQ(wnode.GetIsFolder(), false); | 433 EXPECT_EQ(wnode.GetIsFolder(), false); |
| 419 EXPECT_EQ(wnode.GetParentId(), folder_node.GetId()); | 434 EXPECT_EQ(wnode.GetParentId(), folder_node.GetId()); |
| 420 EXPECT_EQ(wnode.GetId(), node_id); | 435 EXPECT_EQ(wnode.GetId(), node_id); |
| 421 EXPECT_NE(wnode.GetTitle(), test_title); // Title should be cleared | 436 EXPECT_NE(wnode.GetTitle(), test_title); // Title should be cleared |
| 422 wnode.SetTitle(UTF8ToWide(test_title)); | 437 wnode.SetTitle(UTF8ToWide(test_title)); |
| 423 } | 438 } |
| 424 | 439 |
| 425 // Now look up should work. | 440 // Now look up should work. |
| 426 { | 441 { |
| 427 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 442 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 428 ReadNode node(&trans); | 443 ReadNode node(&trans); |
| 429 EXPECT_EQ(BaseNode::INIT_OK, | 444 EXPECT_EQ(BaseNode::INIT_OK, |
| 430 node.InitByClientTagLookup(BOOKMARKS, | 445 node.InitByClientTagLookup(AUTOFILL, |
| 431 "testtag")); | 446 "testtag")); |
| 432 EXPECT_EQ(node.GetTitle(), test_title); | 447 EXPECT_EQ(node.GetTitle(), test_title); |
| 433 EXPECT_EQ(node.GetModelType(), BOOKMARKS); | 448 EXPECT_EQ(node.GetModelType(), AUTOFILL); |
| 434 } | 449 } |
| 435 } | 450 } |
| 436 | 451 |
| 437 TEST_F(SyncApiTest, WriteAndReadPassword) { | 452 TEST_F(SyncApiTest, WriteAndReadPassword) { |
| 438 KeyParams params = {"localhost", "username", "passphrase"}; | 453 KeyParams params = {"localhost", "username", "passphrase"}; |
| 439 { | 454 { |
| 440 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 455 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 441 trans.GetCryptographer()->AddKey(params); | 456 trans.GetCryptographer()->AddKey(params); |
| 442 } | 457 } |
| 443 { | 458 { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 468 } | 483 } |
| 469 } | 484 } |
| 470 | 485 |
| 471 TEST_F(SyncApiTest, WriteEncryptedTitle) { | 486 TEST_F(SyncApiTest, WriteEncryptedTitle) { |
| 472 KeyParams params = {"localhost", "username", "passphrase"}; | 487 KeyParams params = {"localhost", "username", "passphrase"}; |
| 473 { | 488 { |
| 474 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 489 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 475 trans.GetCryptographer()->AddKey(params); | 490 trans.GetCryptographer()->AddKey(params); |
| 476 } | 491 } |
| 477 test_user_share_.encryption_handler()->EnableEncryptEverything(); | 492 test_user_share_.encryption_handler()->EnableEncryptEverything(); |
| 493 int bookmark_id; |
| 478 { | 494 { |
| 479 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 495 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 480 ReadNode root_node(&trans); | 496 ReadNode root_node(&trans); |
| 481 root_node.InitByRootLookup(); | 497 root_node.InitByRootLookup(); |
| 482 | 498 |
| 483 WriteNode bookmark_node(&trans); | 499 WriteNode bookmark_node(&trans); |
| 484 WriteNode::InitUniqueByCreationResult result = | 500 EXPECT_TRUE(bookmark_node.InitBookmarkByCreation(root_node, NULL)); |
| 485 bookmark_node.InitUniqueByCreation(BOOKMARKS, | 501 bookmark_id = bookmark_node.GetId(); |
| 486 root_node, "foo"); | |
| 487 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); | |
| 488 bookmark_node.SetTitle(UTF8ToWide("foo")); | 502 bookmark_node.SetTitle(UTF8ToWide("foo")); |
| 489 | 503 |
| 490 WriteNode pref_node(&trans); | 504 WriteNode pref_node(&trans); |
| 491 result = | 505 WriteNode::InitUniqueByCreationResult result = |
| 492 pref_node.InitUniqueByCreation(PREFERENCES, root_node, "bar"); | 506 pref_node.InitUniqueByCreation(PREFERENCES, root_node, "bar"); |
| 493 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); | 507 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 494 pref_node.SetTitle(UTF8ToWide("bar")); | 508 pref_node.SetTitle(UTF8ToWide("bar")); |
| 495 } | 509 } |
| 496 { | 510 { |
| 497 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 511 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 498 ReadNode root_node(&trans); | 512 ReadNode root_node(&trans); |
| 499 root_node.InitByRootLookup(); | 513 root_node.InitByRootLookup(); |
| 500 | 514 |
| 501 ReadNode bookmark_node(&trans); | 515 ReadNode bookmark_node(&trans); |
| 502 EXPECT_EQ(BaseNode::INIT_OK, | 516 EXPECT_EQ(BaseNode::INIT_OK, |
| 503 bookmark_node.InitByClientTagLookup(BOOKMARKS, | 517 bookmark_node.InitByIdLookup(bookmark_id)); |
| 504 "foo")); | |
| 505 EXPECT_EQ("foo", bookmark_node.GetTitle()); | 518 EXPECT_EQ("foo", bookmark_node.GetTitle()); |
| 506 EXPECT_EQ(kEncryptedString, | 519 EXPECT_EQ(kEncryptedString, |
| 507 bookmark_node.GetEntry()->Get(syncable::NON_UNIQUE_NAME)); | 520 bookmark_node.GetEntry()->Get(syncable::NON_UNIQUE_NAME)); |
| 508 | 521 |
| 509 ReadNode pref_node(&trans); | 522 ReadNode pref_node(&trans); |
| 510 EXPECT_EQ(BaseNode::INIT_OK, | 523 EXPECT_EQ(BaseNode::INIT_OK, |
| 511 pref_node.InitByClientTagLookup(PREFERENCES, | 524 pref_node.InitByClientTagLookup(PREFERENCES, |
| 512 "bar")); | 525 "bar")); |
| 513 EXPECT_EQ(kEncryptedString, pref_node.GetTitle()); | 526 EXPECT_EQ(kEncryptedString, pref_node.GetTitle()); |
| 514 } | 527 } |
| 515 } | 528 } |
| 516 | 529 |
| 517 TEST_F(SyncApiTest, BaseNodeSetSpecifics) { | 530 TEST_F(SyncApiTest, BaseNodeSetSpecifics) { |
| 518 int64 child_id = MakeNode(test_user_share_.user_share(), | 531 int64 child_id = MakeNode(test_user_share_.user_share(), |
| 519 BOOKMARKS, "testtag"); | 532 THEMES, "testtag"); |
| 520 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 533 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 521 WriteNode node(&trans); | 534 WriteNode node(&trans); |
| 522 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); | 535 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); |
| 523 | 536 |
| 537 |
| 524 sync_pb::EntitySpecifics entity_specifics; | 538 sync_pb::EntitySpecifics entity_specifics; |
| 525 entity_specifics.mutable_bookmark()->set_url("http://www.google.com"); | 539 entity_specifics.mutable_theme()->set_custom_theme_name("ThemeName"); |
| 526 | 540 |
| 527 EXPECT_NE(entity_specifics.SerializeAsString(), | 541 EXPECT_NE(entity_specifics.SerializeAsString(), |
| 528 node.GetEntitySpecifics().SerializeAsString()); | 542 node.GetEntitySpecifics().SerializeAsString()); |
| 529 node.SetEntitySpecifics(entity_specifics); | 543 node.SetEntitySpecifics(entity_specifics); |
| 530 EXPECT_EQ(entity_specifics.SerializeAsString(), | 544 EXPECT_EQ(entity_specifics.SerializeAsString(), |
| 531 node.GetEntitySpecifics().SerializeAsString()); | 545 node.GetEntitySpecifics().SerializeAsString()); |
| 532 } | 546 } |
| 533 | 547 |
| 534 TEST_F(SyncApiTest, BaseNodeSetSpecificsPreservesUnknownFields) { | 548 TEST_F(SyncApiTest, BaseNodeSetSpecificsPreservesUnknownFields) { |
| 535 int64 child_id = MakeNode(test_user_share_.user_share(), | 549 int64 child_id = MakeNode(test_user_share_.user_share(), |
| 536 BOOKMARKS, "testtag"); | 550 THEMES, "testtag"); |
| 537 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 551 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 538 WriteNode node(&trans); | 552 WriteNode node(&trans); |
| 539 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); | 553 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); |
| 540 EXPECT_TRUE(node.GetEntitySpecifics().unknown_fields().empty()); | 554 EXPECT_TRUE(node.GetEntitySpecifics().unknown_fields().empty()); |
| 541 | 555 |
| 542 sync_pb::EntitySpecifics entity_specifics; | 556 sync_pb::EntitySpecifics entity_specifics; |
| 543 entity_specifics.mutable_bookmark()->set_url("http://www.google.com"); | 557 entity_specifics.mutable_theme()->set_custom_theme_name("ThemeName"); |
| 544 entity_specifics.mutable_unknown_fields()->AddFixed32(5, 100); | 558 entity_specifics.mutable_unknown_fields()->AddFixed32(5, 100); |
| 545 node.SetEntitySpecifics(entity_specifics); | 559 node.SetEntitySpecifics(entity_specifics); |
| 546 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); | 560 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); |
| 547 | 561 |
| 548 entity_specifics.mutable_unknown_fields()->Clear(); | 562 entity_specifics.mutable_unknown_fields()->Clear(); |
| 549 node.SetEntitySpecifics(entity_specifics); | 563 node.SetEntitySpecifics(entity_specifics); |
| 550 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); | 564 EXPECT_FALSE(node.GetEntitySpecifics().unknown_fields().empty()); |
| 551 } | 565 } |
| 552 | 566 |
| 553 namespace { | 567 namespace { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 573 } else if (expected_model_type == UNSPECIFIED) { | 587 } else if (expected_model_type == UNSPECIFIED) { |
| 574 EXPECT_EQ("Unspecified", type_str); | 588 EXPECT_EQ("Unspecified", type_str); |
| 575 } else { | 589 } else { |
| 576 ADD_FAILURE(); | 590 ADD_FAILURE(); |
| 577 } | 591 } |
| 578 } | 592 } |
| 579 if (is_detailed) { | 593 if (is_detailed) { |
| 580 ExpectInt64Value(node.GetParentId(), value, "parentId"); | 594 ExpectInt64Value(node.GetParentId(), value, "parentId"); |
| 581 ExpectTimeValue(node.GetModificationTime(), value, "modificationTime"); | 595 ExpectTimeValue(node.GetModificationTime(), value, "modificationTime"); |
| 582 ExpectInt64Value(node.GetExternalId(), value, "externalId"); | 596 ExpectInt64Value(node.GetExternalId(), value, "externalId"); |
| 583 ExpectInt64Value(node.GetPredecessorId(), value, "predecessorId"); | |
| 584 ExpectInt64Value(node.GetSuccessorId(), value, "successorId"); | |
| 585 ExpectInt64Value(node.GetFirstChildId(), value, "firstChildId"); | |
| 586 { | 597 { |
| 587 scoped_ptr<DictionaryValue> expected_entry( | 598 scoped_ptr<DictionaryValue> expected_entry( |
| 588 node.GetEntry()->ToValue(NULL)); | 599 node.GetEntry()->ToValue(NULL)); |
| 589 const Value* entry = NULL; | 600 const Value* entry = NULL; |
| 590 EXPECT_TRUE(value.Get("entry", &entry)); | 601 EXPECT_TRUE(value.Get("entry", &entry)); |
| 591 EXPECT_TRUE(Value::Equals(entry, expected_entry.get())); | 602 EXPECT_TRUE(Value::Equals(entry, expected_entry.get())); |
| 592 } | 603 } |
| 593 EXPECT_EQ(11u, value.size()); | 604 EXPECT_EQ(8u, value.size()); |
| 594 } else { | 605 } else { |
| 595 EXPECT_EQ(4u, value.size()); | 606 EXPECT_EQ(4u, value.size()); |
| 596 } | 607 } |
| 597 } | 608 } |
| 598 | 609 |
| 599 } // namespace | 610 } // namespace |
| 600 | 611 |
| 601 TEST_F(SyncApiTest, BaseNodeGetSummaryAsValue) { | 612 TEST_F(SyncApiTest, BaseNodeGetSummaryAsValue) { |
| 602 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 613 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 603 ReadNode node(&trans); | 614 ReadNode node(&trans); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 NULL); | 691 NULL); |
| 681 ignore_result(MakeFolderWithParent(test_user_share_.user_share(), | 692 ignore_result(MakeFolderWithParent(test_user_share_.user_share(), |
| 682 BOOKMARKS, | 693 BOOKMARKS, |
| 683 type_root, | 694 type_root, |
| 684 NULL)); | 695 NULL)); |
| 685 int64 child1 = MakeFolderWithParent( | 696 int64 child1 = MakeFolderWithParent( |
| 686 test_user_share_.user_share(), | 697 test_user_share_.user_share(), |
| 687 BOOKMARKS, | 698 BOOKMARKS, |
| 688 parent, | 699 parent, |
| 689 NULL); | 700 NULL); |
| 690 ignore_result(MakeNodeWithParent( | 701 ignore_result(MakeBookmarkWithParent( |
| 691 test_user_share_.user_share(), | 702 test_user_share_.user_share(), |
| 692 BOOKMARKS, | 703 parent, |
| 693 "c2", | 704 NULL)); |
| 694 parent)); | 705 ignore_result(MakeBookmarkWithParent( |
| 695 ignore_result(MakeNodeWithParent( | |
| 696 test_user_share_.user_share(), | 706 test_user_share_.user_share(), |
| 697 BOOKMARKS, | 707 child1, |
| 698 "c1c1", | 708 NULL)); |
| 699 child1)); | |
| 700 | 709 |
| 701 { | 710 { |
| 702 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 711 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
| 703 ReadNode type_root_node(&trans); | 712 ReadNode type_root_node(&trans); |
| 704 EXPECT_EQ(BaseNode::INIT_OK, | 713 EXPECT_EQ(BaseNode::INIT_OK, |
| 705 type_root_node.InitByIdLookup(type_root)); | 714 type_root_node.InitByIdLookup(type_root)); |
| 706 EXPECT_EQ(6, type_root_node.GetTotalNodeCount()); | 715 EXPECT_EQ(6, type_root_node.GetTotalNodeCount()); |
| 707 ReadNode node(&trans); | 716 ReadNode node(&trans); |
| 708 EXPECT_EQ(BaseNode::INIT_OK, | 717 EXPECT_EQ(BaseNode::INIT_OK, |
| 709 node.InitByIdLookup(parent)); | 718 node.InitByIdLookup(parent)); |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 } | 958 } |
| 950 | 959 |
| 951 // Looks up an entry by client tag and resets IS_UNSYNCED value to false. | 960 // Looks up an entry by client tag and resets IS_UNSYNCED value to false. |
| 952 // Returns true if entry was previously unsynced, false if IS_UNSYNCED was | 961 // Returns true if entry was previously unsynced, false if IS_UNSYNCED was |
| 953 // already false. | 962 // already false. |
| 954 bool ResetUnsyncedEntry(ModelType type, | 963 bool ResetUnsyncedEntry(ModelType type, |
| 955 const std::string& client_tag) { | 964 const std::string& client_tag) { |
| 956 UserShare* share = sync_manager_.GetUserShare(); | 965 UserShare* share = sync_manager_.GetUserShare(); |
| 957 syncable::WriteTransaction trans( | 966 syncable::WriteTransaction trans( |
| 958 FROM_HERE, syncable::UNITTEST, share->directory.get()); | 967 FROM_HERE, syncable::UNITTEST, share->directory.get()); |
| 959 const std::string hash = BaseNode::GenerateSyncableHash(type, client_tag); | 968 const std::string hash = syncable::GenerateSyncableHash(type, client_tag); |
| 960 syncable::MutableEntry entry(&trans, syncable::GET_BY_CLIENT_TAG, | 969 syncable::MutableEntry entry(&trans, syncable::GET_BY_CLIENT_TAG, |
| 961 hash); | 970 hash); |
| 962 EXPECT_TRUE(entry.good()); | 971 EXPECT_TRUE(entry.good()); |
| 963 if (!entry.Get(IS_UNSYNCED)) | 972 if (!entry.Get(IS_UNSYNCED)) |
| 964 return false; | 973 return false; |
| 965 entry.Put(IS_UNSYNCED, false); | 974 entry.Put(IS_UNSYNCED, false); |
| 966 return true; | 975 return true; |
| 967 } | 976 } |
| 968 | 977 |
| 969 virtual InternalComponentsFactory* GetFactory() { | 978 virtual InternalComponentsFactory* GetFactory() { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 void RunGetNodesByIdTest(const char* message_name, bool is_detailed) { | 1141 void RunGetNodesByIdTest(const char* message_name, bool is_detailed) { |
| 1133 int64 root_id = kInvalidId; | 1142 int64 root_id = kInvalidId; |
| 1134 { | 1143 { |
| 1135 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1144 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1136 ReadNode root_node(&trans); | 1145 ReadNode root_node(&trans); |
| 1137 root_node.InitByRootLookup(); | 1146 root_node.InitByRootLookup(); |
| 1138 root_id = root_node.GetId(); | 1147 root_id = root_node.GetId(); |
| 1139 } | 1148 } |
| 1140 | 1149 |
| 1141 int64 child_id = | 1150 int64 child_id = |
| 1142 MakeNode(sync_manager_.GetUserShare(), BOOKMARKS, "testtag"); | 1151 MakeNode(sync_manager_.GetUserShare(), THEMES, "testtag"); |
| 1143 | 1152 |
| 1144 StrictMock<MockJsReplyHandler> reply_handler; | 1153 StrictMock<MockJsReplyHandler> reply_handler; |
| 1145 | 1154 |
| 1146 JsArgList return_args; | 1155 JsArgList return_args; |
| 1147 | 1156 |
| 1148 const int64 ids[] = { root_id, child_id }; | 1157 const int64 ids[] = { root_id, child_id }; |
| 1149 | 1158 |
| 1150 EXPECT_CALL(reply_handler, | 1159 EXPECT_CALL(reply_handler, |
| 1151 HandleJsReply(message_name, _)) | 1160 HandleJsReply(message_name, _)) |
| 1152 .Times(arraysize(ids)).WillRepeatedly(SaveArg<1>(&return_args)); | 1161 .Times(arraysize(ids)).WillRepeatedly(SaveArg<1>(&return_args)); |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1547 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1556 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 1548 | 1557 |
| 1549 // Create some unencrypted unsynced data. | 1558 // Create some unencrypted unsynced data. |
| 1550 int64 folder = MakeFolderWithParent(sync_manager_.GetUserShare(), | 1559 int64 folder = MakeFolderWithParent(sync_manager_.GetUserShare(), |
| 1551 BOOKMARKS, | 1560 BOOKMARKS, |
| 1552 GetIdForDataType(BOOKMARKS), | 1561 GetIdForDataType(BOOKMARKS), |
| 1553 NULL); | 1562 NULL); |
| 1554 // First batch_size nodes are children of folder. | 1563 // First batch_size nodes are children of folder. |
| 1555 size_t i; | 1564 size_t i; |
| 1556 for (i = 0; i < batch_size; ++i) { | 1565 for (i = 0; i < batch_size; ++i) { |
| 1557 MakeNodeWithParent(sync_manager_.GetUserShare(), BOOKMARKS, | 1566 MakeNodeWithParent(sync_manager_.GetUserShare(), BOOKMARKS, folder); |
| 1558 base::StringPrintf("%"PRIuS"", i), folder); | |
| 1559 } | 1567 } |
| 1560 // Next batch_size nodes are a different type and on their own. | 1568 // Next batch_size nodes are a different type and on their own. |
| 1561 for (; i < 2*batch_size; ++i) { | 1569 for (; i < 2*batch_size; ++i) { |
| 1562 MakeNodeWithParent(sync_manager_.GetUserShare(), SESSIONS, | 1570 MakeNode(sync_manager_.GetUserShare(), SESSIONS, |
| 1563 base::StringPrintf("%"PRIuS"", i), | 1571 base::StringPrintf("%"PRIuS"", i)); |
| 1564 GetIdForDataType(SESSIONS)); | |
| 1565 } | 1572 } |
| 1566 // Last batch_size nodes are a third type that will not need encryption. | 1573 // Last batch_size nodes are a third type that will not need encryption. |
| 1567 for (; i < 3*batch_size; ++i) { | 1574 for (; i < 3*batch_size; ++i) { |
| 1568 MakeNodeWithParent(sync_manager_.GetUserShare(), THEMES, | 1575 MakeNode(sync_manager_.GetUserShare(), THEMES, |
| 1569 base::StringPrintf("%"PRIuS"", i), | 1576 base::StringPrintf("%"PRIuS"", i)); |
| 1570 GetIdForDataType(THEMES)); | |
| 1571 } | 1577 } |
| 1572 | 1578 |
| 1573 { | 1579 { |
| 1574 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1580 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1575 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals( | 1581 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals( |
| 1576 SyncEncryptionHandler::SensitiveTypes())); | 1582 SyncEncryptionHandler::SensitiveTypes())); |
| 1577 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1583 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1578 trans.GetWrappedTrans(), | 1584 trans.GetWrappedTrans(), |
| 1579 BOOKMARKS, | 1585 BOOKMARKS, |
| 1580 false /* not encrypted */)); | 1586 false /* not encrypted */)); |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2056 TEST_F(SyncManagerTest, EncryptBookmarksWithLegacyData) { | 2062 TEST_F(SyncManagerTest, EncryptBookmarksWithLegacyData) { |
| 2057 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2063 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2058 std::string title; | 2064 std::string title; |
| 2059 SyncAPINameToServerName("Google", &title); | 2065 SyncAPINameToServerName("Google", &title); |
| 2060 std::string url = "http://www.google.com"; | 2066 std::string url = "http://www.google.com"; |
| 2061 std::string raw_title2 = ".."; // An invalid cosmo title. | 2067 std::string raw_title2 = ".."; // An invalid cosmo title. |
| 2062 std::string title2; | 2068 std::string title2; |
| 2063 SyncAPINameToServerName(raw_title2, &title2); | 2069 SyncAPINameToServerName(raw_title2, &title2); |
| 2064 std::string url2 = "http://www.bla.com"; | 2070 std::string url2 = "http://www.bla.com"; |
| 2065 | 2071 |
| 2072 int64 parent = GetServerNodeForType(sync_manager_.GetUserShare(), BOOKMARKS); |
| 2073 |
| 2066 // Create a bookmark using the legacy format. | 2074 // Create a bookmark using the legacy format. |
| 2067 int64 node_id1 = MakeNode(sync_manager_.GetUserShare(), | 2075 int64 node_id1 = MakeBookmarkWithParent(sync_manager_.GetUserShare(), |
| 2068 BOOKMARKS, | 2076 parent, NULL); |
| 2069 "testtag"); | 2077 int64 node_id2 = MakeBookmarkWithParent(sync_manager_.GetUserShare(), |
| 2070 int64 node_id2 = MakeNode(sync_manager_.GetUserShare(), | 2078 parent, NULL); |
| 2071 BOOKMARKS, | |
| 2072 "testtag2"); | |
| 2073 { | 2079 { |
| 2074 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2080 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2075 WriteNode node(&trans); | 2081 WriteNode node(&trans); |
| 2076 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(node_id1)); | 2082 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(node_id1)); |
| 2077 | 2083 |
| 2078 sync_pb::EntitySpecifics entity_specifics; | 2084 sync_pb::EntitySpecifics entity_specifics; |
| 2079 entity_specifics.mutable_bookmark()->set_url(url); | 2085 entity_specifics.mutable_bookmark()->set_url(url); |
| 2080 node.SetEntitySpecifics(entity_specifics); | 2086 node.SetEntitySpecifics(entity_specifics); |
| 2081 | 2087 |
| 2082 // Set the old style title. | 2088 // Set the old style title. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2157 } | 2163 } |
| 2158 | 2164 |
| 2159 // Create a bookmark and set the title/url, then verify the data was properly | 2165 // Create a bookmark and set the title/url, then verify the data was properly |
| 2160 // set. This replicates the unique way bookmarks have of creating sync nodes. | 2166 // set. This replicates the unique way bookmarks have of creating sync nodes. |
| 2161 // See BookmarkChangeProcessor::PlaceSyncNode(..). | 2167 // See BookmarkChangeProcessor::PlaceSyncNode(..). |
| 2162 TEST_F(SyncManagerTest, CreateLocalBookmark) { | 2168 TEST_F(SyncManagerTest, CreateLocalBookmark) { |
| 2163 std::string title = "title"; | 2169 std::string title = "title"; |
| 2164 std::string url = "url"; | 2170 std::string url = "url"; |
| 2165 { | 2171 { |
| 2166 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2172 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2167 ReadNode root_node(&trans); | 2173 ReadNode bookmark_root(&trans); |
| 2168 root_node.InitByRootLookup(); | 2174 ASSERT_EQ(BaseNode::INIT_OK, |
| 2175 bookmark_root.InitByTagLookup(ModelTypeToRootTag(BOOKMARKS))); |
| 2169 WriteNode node(&trans); | 2176 WriteNode node(&trans); |
| 2170 ASSERT_TRUE(node.InitByCreation(BOOKMARKS, root_node, NULL)); | 2177 ASSERT_TRUE(node.InitBookmarkByCreation(bookmark_root, NULL)); |
| 2171 node.SetIsFolder(false); | 2178 node.SetIsFolder(false); |
| 2172 node.SetTitle(UTF8ToWide(title)); | 2179 node.SetTitle(UTF8ToWide(title)); |
| 2173 | 2180 |
| 2174 sync_pb::BookmarkSpecifics bookmark_specifics(node.GetBookmarkSpecifics()); | 2181 sync_pb::BookmarkSpecifics bookmark_specifics(node.GetBookmarkSpecifics()); |
| 2175 bookmark_specifics.set_url(url); | 2182 bookmark_specifics.set_url(url); |
| 2176 node.SetBookmarkSpecifics(bookmark_specifics); | 2183 node.SetBookmarkSpecifics(bookmark_specifics); |
| 2177 } | 2184 } |
| 2178 { | 2185 { |
| 2179 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2186 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2180 ReadNode root_node(&trans); | 2187 ReadNode bookmark_root(&trans); |
| 2181 root_node.InitByRootLookup(); | 2188 ASSERT_EQ(BaseNode::INIT_OK, |
| 2182 int64 child_id = root_node.GetFirstChildId(); | 2189 bookmark_root.InitByTagLookup(ModelTypeToRootTag(BOOKMARKS))); |
| 2190 int64 child_id = bookmark_root.GetFirstChildId(); |
| 2183 | 2191 |
| 2184 ReadNode node(&trans); | 2192 ReadNode node(&trans); |
| 2185 ASSERT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); | 2193 ASSERT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(child_id)); |
| 2186 EXPECT_FALSE(node.GetIsFolder()); | 2194 EXPECT_FALSE(node.GetIsFolder()); |
| 2187 EXPECT_EQ(title, node.GetTitle()); | 2195 EXPECT_EQ(title, node.GetTitle()); |
| 2188 EXPECT_EQ(url, node.GetBookmarkSpecifics().url()); | 2196 EXPECT_EQ(url, node.GetBookmarkSpecifics().url()); |
| 2189 } | 2197 } |
| 2190 } | 2198 } |
| 2191 | 2199 |
| 2192 // Verifies WriteNode::UpdateEntryWithEncryption does not make unnecessary | 2200 // Verifies WriteNode::UpdateEntryWithEncryption does not make unnecessary |
| 2193 // changes. | 2201 // changes. |
| 2194 TEST_F(SyncManagerTest, UpdateEntryWithEncryption) { | 2202 TEST_F(SyncManagerTest, UpdateEntryWithEncryption) { |
| 2195 std::string client_tag = "title"; | 2203 std::string client_tag = "title"; |
| 2196 sync_pb::EntitySpecifics entity_specifics; | 2204 sync_pb::EntitySpecifics entity_specifics; |
| 2197 entity_specifics.mutable_bookmark()->set_url("url"); | 2205 entity_specifics.mutable_bookmark()->set_url("url"); |
| 2198 entity_specifics.mutable_bookmark()->set_title("title"); | 2206 entity_specifics.mutable_bookmark()->set_title("title"); |
| 2199 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, | 2207 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, |
| 2200 BaseNode::GenerateSyncableHash(BOOKMARKS, | 2208 syncable::GenerateSyncableHash(BOOKMARKS, |
| 2201 client_tag), | 2209 client_tag), |
| 2202 entity_specifics); | 2210 entity_specifics); |
| 2203 // New node shouldn't start off unsynced. | 2211 // New node shouldn't start off unsynced. |
| 2204 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); | 2212 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2205 // Manually change to the same data. Should not set is_unsynced. | 2213 // Manually change to the same data. Should not set is_unsynced. |
| 2206 { | 2214 { |
| 2207 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2215 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2208 WriteNode node(&trans); | 2216 WriteNode node(&trans); |
| 2209 EXPECT_EQ(BaseNode::INIT_OK, | 2217 EXPECT_EQ(BaseNode::INIT_OK, |
| 2210 node.InitByClientTagLookup(BOOKMARKS, client_tag)); | 2218 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2339 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2347 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2340 Cryptographer* cryptographer = trans.GetCryptographer(); | 2348 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2341 sync_pb::PasswordSpecificsData data; | 2349 sync_pb::PasswordSpecificsData data; |
| 2342 data.set_password_value("secret"); | 2350 data.set_password_value("secret"); |
| 2343 cryptographer->Encrypt( | 2351 cryptographer->Encrypt( |
| 2344 data, | 2352 data, |
| 2345 entity_specifics.mutable_password()-> | 2353 entity_specifics.mutable_password()-> |
| 2346 mutable_encrypted()); | 2354 mutable_encrypted()); |
| 2347 } | 2355 } |
| 2348 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, | 2356 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, |
| 2349 BaseNode::GenerateSyncableHash(PASSWORDS, | 2357 syncable::GenerateSyncableHash(PASSWORDS, |
| 2350 client_tag), | 2358 client_tag), |
| 2351 entity_specifics); | 2359 entity_specifics); |
| 2352 // New node shouldn't start off unsynced. | 2360 // New node shouldn't start off unsynced. |
| 2353 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2361 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2354 | 2362 |
| 2355 // Manually change to the same data via SetEntitySpecifics. Should not set | 2363 // Manually change to the same data via SetEntitySpecifics. Should not set |
| 2356 // is_unsynced. | 2364 // is_unsynced. |
| 2357 { | 2365 { |
| 2358 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2366 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2359 WriteNode node(&trans); | 2367 WriteNode node(&trans); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2374 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2382 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2375 Cryptographer* cryptographer = trans.GetCryptographer(); | 2383 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2376 sync_pb::PasswordSpecificsData data; | 2384 sync_pb::PasswordSpecificsData data; |
| 2377 data.set_password_value("secret"); | 2385 data.set_password_value("secret"); |
| 2378 cryptographer->Encrypt( | 2386 cryptographer->Encrypt( |
| 2379 data, | 2387 data, |
| 2380 entity_specifics.mutable_password()-> | 2388 entity_specifics.mutable_password()-> |
| 2381 mutable_encrypted()); | 2389 mutable_encrypted()); |
| 2382 } | 2390 } |
| 2383 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, | 2391 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, |
| 2384 BaseNode::GenerateSyncableHash(PASSWORDS, | 2392 syncable::GenerateSyncableHash(PASSWORDS, |
| 2385 client_tag), | 2393 client_tag), |
| 2386 entity_specifics); | 2394 entity_specifics); |
| 2387 // New node shouldn't start off unsynced. | 2395 // New node shouldn't start off unsynced. |
| 2388 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2396 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2389 | 2397 |
| 2390 // Manually change to the same data via SetPasswordSpecifics. Should not set | 2398 // Manually change to the same data via SetPasswordSpecifics. Should not set |
| 2391 // is_unsynced. | 2399 // is_unsynced. |
| 2392 { | 2400 { |
| 2393 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2401 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2394 WriteNode node(&trans); | 2402 WriteNode node(&trans); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2425 { | 2433 { |
| 2426 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2434 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2427 Cryptographer* cryptographer = trans.GetCryptographer(); | 2435 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2428 sync_pb::PasswordSpecificsData data; | 2436 sync_pb::PasswordSpecificsData data; |
| 2429 data.set_password_value("secret"); | 2437 data.set_password_value("secret"); |
| 2430 cryptographer->Encrypt( | 2438 cryptographer->Encrypt( |
| 2431 data, | 2439 data, |
| 2432 entity_specifics.mutable_password()->mutable_encrypted()); | 2440 entity_specifics.mutable_password()->mutable_encrypted()); |
| 2433 } | 2441 } |
| 2434 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, | 2442 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, |
| 2435 BaseNode::GenerateSyncableHash(PASSWORDS, | 2443 syncable::GenerateSyncableHash(PASSWORDS, |
| 2436 client_tag), | 2444 client_tag), |
| 2437 entity_specifics); | 2445 entity_specifics); |
| 2438 // New node shouldn't start off unsynced. | 2446 // New node shouldn't start off unsynced. |
| 2439 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2447 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2440 | 2448 |
| 2441 // Set a new passphrase. Should set is_unsynced. | 2449 // Set a new passphrase. Should set is_unsynced. |
| 2442 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 2450 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 2443 EXPECT_CALL(encryption_observer_, | 2451 EXPECT_CALL(encryption_observer_, |
| 2444 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 2452 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 2445 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 2453 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2464 { | 2472 { |
| 2465 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2473 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2466 Cryptographer* cryptographer = trans.GetCryptographer(); | 2474 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2467 sync_pb::PasswordSpecificsData data; | 2475 sync_pb::PasswordSpecificsData data; |
| 2468 data.set_password_value("secret"); | 2476 data.set_password_value("secret"); |
| 2469 cryptographer->Encrypt( | 2477 cryptographer->Encrypt( |
| 2470 data, | 2478 data, |
| 2471 entity_specifics.mutable_password()->mutable_encrypted()); | 2479 entity_specifics.mutable_password()->mutable_encrypted()); |
| 2472 } | 2480 } |
| 2473 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, | 2481 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, |
| 2474 BaseNode::GenerateSyncableHash(PASSWORDS, | 2482 syncable::GenerateSyncableHash(PASSWORDS, |
| 2475 client_tag), | 2483 client_tag), |
| 2476 entity_specifics); | 2484 entity_specifics); |
| 2477 // New node shouldn't start off unsynced. | 2485 // New node shouldn't start off unsynced. |
| 2478 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2486 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2479 | 2487 |
| 2480 // Force a re-encrypt everything. Should not set is_unsynced. | 2488 // Force a re-encrypt everything. Should not set is_unsynced. |
| 2481 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 2489 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 2482 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 2490 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2483 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 2491 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2484 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); | 2492 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); |
| 2485 sync_manager_.GetEncryptionHandler()->Init(); | 2493 sync_manager_.GetEncryptionHandler()->Init(); |
| 2486 PumpLoop(); | 2494 PumpLoop(); |
| 2487 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2495 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2488 } | 2496 } |
| 2489 | 2497 |
| 2490 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for bookmarks | 2498 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for bookmarks |
| 2491 // when we write the same data, but does set it when we write new data. | 2499 // when we write the same data, but does set it when we write new data. |
| 2492 TEST_F(SyncManagerTest, SetBookmarkTitle) { | 2500 TEST_F(SyncManagerTest, SetBookmarkTitle) { |
| 2493 std::string client_tag = "title"; | 2501 std::string client_tag = "title"; |
| 2494 sync_pb::EntitySpecifics entity_specifics; | 2502 sync_pb::EntitySpecifics entity_specifics; |
| 2495 entity_specifics.mutable_bookmark()->set_url("url"); | 2503 entity_specifics.mutable_bookmark()->set_url("url"); |
| 2496 entity_specifics.mutable_bookmark()->set_title("title"); | 2504 entity_specifics.mutable_bookmark()->set_title("title"); |
| 2497 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, | 2505 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, |
| 2498 BaseNode::GenerateSyncableHash(BOOKMARKS, | 2506 syncable::GenerateSyncableHash(BOOKMARKS, |
| 2499 client_tag), | 2507 client_tag), |
| 2500 entity_specifics); | 2508 entity_specifics); |
| 2501 // New node shouldn't start off unsynced. | 2509 // New node shouldn't start off unsynced. |
| 2502 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); | 2510 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2503 | 2511 |
| 2504 // Manually change to the same title. Should not set is_unsynced. | 2512 // Manually change to the same title. Should not set is_unsynced. |
| 2505 { | 2513 { |
| 2506 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2514 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2507 WriteNode node(&trans); | 2515 WriteNode node(&trans); |
| 2508 EXPECT_EQ(BaseNode::INIT_OK, | 2516 EXPECT_EQ(BaseNode::INIT_OK, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2524 | 2532 |
| 2525 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted | 2533 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for encrypted |
| 2526 // bookmarks when we write the same data, but does set it when we write new | 2534 // bookmarks when we write the same data, but does set it when we write new |
| 2527 // data. | 2535 // data. |
| 2528 TEST_F(SyncManagerTest, SetBookmarkTitleWithEncryption) { | 2536 TEST_F(SyncManagerTest, SetBookmarkTitleWithEncryption) { |
| 2529 std::string client_tag = "title"; | 2537 std::string client_tag = "title"; |
| 2530 sync_pb::EntitySpecifics entity_specifics; | 2538 sync_pb::EntitySpecifics entity_specifics; |
| 2531 entity_specifics.mutable_bookmark()->set_url("url"); | 2539 entity_specifics.mutable_bookmark()->set_url("url"); |
| 2532 entity_specifics.mutable_bookmark()->set_title("title"); | 2540 entity_specifics.mutable_bookmark()->set_title("title"); |
| 2533 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, | 2541 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, |
| 2534 BaseNode::GenerateSyncableHash(BOOKMARKS, | 2542 syncable::GenerateSyncableHash(BOOKMARKS, |
| 2535 client_tag), | 2543 client_tag), |
| 2536 entity_specifics); | 2544 entity_specifics); |
| 2537 // New node shouldn't start off unsynced. | 2545 // New node shouldn't start off unsynced. |
| 2538 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); | 2546 EXPECT_FALSE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2539 | 2547 |
| 2540 // Encrypt the datatatype, should set is_unsynced. | 2548 // Encrypt the datatatype, should set is_unsynced. |
| 2541 EXPECT_CALL(encryption_observer_, | 2549 EXPECT_CALL(encryption_observer_, |
| 2542 OnEncryptedTypesChanged( | 2550 OnEncryptedTypesChanged( |
| 2543 HasModelTypes(EncryptableUserTypes()), true)); | 2551 HasModelTypes(EncryptableUserTypes()), true)); |
| 2544 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 2552 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2583 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for non-bookmarks | 2591 // Verify SetTitle(..) doesn't unnecessarily set IS_UNSYNCED for non-bookmarks |
| 2584 // when we write the same data, but does set it when we write new data. | 2592 // when we write the same data, but does set it when we write new data. |
| 2585 TEST_F(SyncManagerTest, SetNonBookmarkTitle) { | 2593 TEST_F(SyncManagerTest, SetNonBookmarkTitle) { |
| 2586 std::string client_tag = "title"; | 2594 std::string client_tag = "title"; |
| 2587 sync_pb::EntitySpecifics entity_specifics; | 2595 sync_pb::EntitySpecifics entity_specifics; |
| 2588 entity_specifics.mutable_preference()->set_name("name"); | 2596 entity_specifics.mutable_preference()->set_name("name"); |
| 2589 entity_specifics.mutable_preference()->set_value("value"); | 2597 entity_specifics.mutable_preference()->set_value("value"); |
| 2590 MakeServerNode(sync_manager_.GetUserShare(), | 2598 MakeServerNode(sync_manager_.GetUserShare(), |
| 2591 PREFERENCES, | 2599 PREFERENCES, |
| 2592 client_tag, | 2600 client_tag, |
| 2593 BaseNode::GenerateSyncableHash(PREFERENCES, | 2601 syncable::GenerateSyncableHash(PREFERENCES, |
| 2594 client_tag), | 2602 client_tag), |
| 2595 entity_specifics); | 2603 entity_specifics); |
| 2596 // New node shouldn't start off unsynced. | 2604 // New node shouldn't start off unsynced. |
| 2597 EXPECT_FALSE(ResetUnsyncedEntry(PREFERENCES, client_tag)); | 2605 EXPECT_FALSE(ResetUnsyncedEntry(PREFERENCES, client_tag)); |
| 2598 | 2606 |
| 2599 // Manually change to the same title. Should not set is_unsynced. | 2607 // Manually change to the same title. Should not set is_unsynced. |
| 2600 { | 2608 { |
| 2601 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2609 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2602 WriteNode node(&trans); | 2610 WriteNode node(&trans); |
| 2603 EXPECT_EQ(BaseNode::INIT_OK, | 2611 EXPECT_EQ(BaseNode::INIT_OK, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2621 // non-bookmarks when we write the same data or when we write new data | 2629 // non-bookmarks when we write the same data or when we write new data |
| 2622 // data (should remained kEncryptedString). | 2630 // data (should remained kEncryptedString). |
| 2623 TEST_F(SyncManagerTest, SetNonBookmarkTitleWithEncryption) { | 2631 TEST_F(SyncManagerTest, SetNonBookmarkTitleWithEncryption) { |
| 2624 std::string client_tag = "title"; | 2632 std::string client_tag = "title"; |
| 2625 sync_pb::EntitySpecifics entity_specifics; | 2633 sync_pb::EntitySpecifics entity_specifics; |
| 2626 entity_specifics.mutable_preference()->set_name("name"); | 2634 entity_specifics.mutable_preference()->set_name("name"); |
| 2627 entity_specifics.mutable_preference()->set_value("value"); | 2635 entity_specifics.mutable_preference()->set_value("value"); |
| 2628 MakeServerNode(sync_manager_.GetUserShare(), | 2636 MakeServerNode(sync_manager_.GetUserShare(), |
| 2629 PREFERENCES, | 2637 PREFERENCES, |
| 2630 client_tag, | 2638 client_tag, |
| 2631 BaseNode::GenerateSyncableHash(PREFERENCES, | 2639 syncable::GenerateSyncableHash(PREFERENCES, |
| 2632 client_tag), | 2640 client_tag), |
| 2633 entity_specifics); | 2641 entity_specifics); |
| 2634 // New node shouldn't start off unsynced. | 2642 // New node shouldn't start off unsynced. |
| 2635 EXPECT_FALSE(ResetUnsyncedEntry(PREFERENCES, client_tag)); | 2643 EXPECT_FALSE(ResetUnsyncedEntry(PREFERENCES, client_tag)); |
| 2636 | 2644 |
| 2637 // Encrypt the datatatype, should set is_unsynced. | 2645 // Encrypt the datatatype, should set is_unsynced. |
| 2638 EXPECT_CALL(encryption_observer_, | 2646 EXPECT_CALL(encryption_observer_, |
| 2639 OnEncryptedTypesChanged( | 2647 OnEncryptedTypesChanged( |
| 2640 HasModelTypes(EncryptableUserTypes()), true)); | 2648 HasModelTypes(EncryptableUserTypes()), true)); |
| 2641 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 2649 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2692 Cryptographer* crypto = trans.GetCryptographer(); | 2700 Cryptographer* crypto = trans.GetCryptographer(); |
| 2693 sync_pb::EntitySpecifics bm_specifics; | 2701 sync_pb::EntitySpecifics bm_specifics; |
| 2694 bm_specifics.mutable_bookmark()->set_title("title"); | 2702 bm_specifics.mutable_bookmark()->set_title("title"); |
| 2695 bm_specifics.mutable_bookmark()->set_url("url"); | 2703 bm_specifics.mutable_bookmark()->set_url("url"); |
| 2696 sync_pb::EncryptedData encrypted; | 2704 sync_pb::EncryptedData encrypted; |
| 2697 crypto->Encrypt(bm_specifics, &encrypted); | 2705 crypto->Encrypt(bm_specifics, &encrypted); |
| 2698 entity_specifics.mutable_encrypted()->CopyFrom(encrypted); | 2706 entity_specifics.mutable_encrypted()->CopyFrom(encrypted); |
| 2699 AddDefaultFieldValue(BOOKMARKS, &entity_specifics); | 2707 AddDefaultFieldValue(BOOKMARKS, &entity_specifics); |
| 2700 } | 2708 } |
| 2701 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, | 2709 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, |
| 2702 BaseNode::GenerateSyncableHash(BOOKMARKS, | 2710 syncable::GenerateSyncableHash(BOOKMARKS, |
| 2703 client_tag), | 2711 client_tag), |
| 2704 entity_specifics); | 2712 entity_specifics); |
| 2705 | 2713 |
| 2706 { | 2714 { |
| 2707 // Verify the data. | 2715 // Verify the data. |
| 2708 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2716 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2709 ReadNode node(&trans); | 2717 ReadNode node(&trans); |
| 2710 EXPECT_EQ(BaseNode::INIT_OK, | 2718 EXPECT_EQ(BaseNode::INIT_OK, |
| 2711 node.InitByClientTagLookup(BOOKMARKS, client_tag)); | 2719 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 2712 EXPECT_EQ(title, node.GetTitle()); | 2720 EXPECT_EQ(title, node.GetTitle()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2757 GetTransactionVersion(i->first)); | 2765 GetTransactionVersion(i->first)); |
| 2758 } | 2766 } |
| 2759 } | 2767 } |
| 2760 | 2768 |
| 2761 // Create bookmark node to increment transaction version of bookmark model. | 2769 // Create bookmark node to increment transaction version of bookmark model. |
| 2762 std::string client_tag = "title"; | 2770 std::string client_tag = "title"; |
| 2763 sync_pb::EntitySpecifics entity_specifics; | 2771 sync_pb::EntitySpecifics entity_specifics; |
| 2764 entity_specifics.mutable_bookmark()->set_url("url"); | 2772 entity_specifics.mutable_bookmark()->set_url("url"); |
| 2765 entity_specifics.mutable_bookmark()->set_title("title"); | 2773 entity_specifics.mutable_bookmark()->set_title("title"); |
| 2766 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, | 2774 MakeServerNode(sync_manager_.GetUserShare(), BOOKMARKS, client_tag, |
| 2767 BaseNode::GenerateSyncableHash(BOOKMARKS, | 2775 syncable::GenerateSyncableHash(BOOKMARKS, |
| 2768 client_tag), | 2776 client_tag), |
| 2769 entity_specifics); | 2777 entity_specifics); |
| 2770 | 2778 |
| 2771 { | 2779 { |
| 2772 ReadTransaction read_trans(FROM_HERE, sync_manager_.GetUserShare()); | 2780 ReadTransaction read_trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2773 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); | 2781 for (ModelSafeRoutingInfo::iterator i = routing_info.begin(); |
| 2774 i != routing_info.end(); ++i) { | 2782 i != routing_info.end(); ++i) { |
| 2775 EXPECT_EQ(i->first == BOOKMARKS ? 2 : 1, | 2783 EXPECT_EQ(i->first == BOOKMARKS ? 2 : 1, |
| 2776 sync_manager_.GetUserShare()->directory-> | 2784 sync_manager_.GetUserShare()->directory-> |
| 2777 GetTransactionVersion(i->first)); | 2785 GetTransactionVersion(i->first)); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3072 Difference(ModelTypeSet::All(), disabled_types); | 3080 Difference(ModelTypeSet::All(), disabled_types); |
| 3073 | 3081 |
| 3074 // Verify only the non-disabled types remain after cleanup. | 3082 // Verify only the non-disabled types remain after cleanup. |
| 3075 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); | 3083 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); |
| 3076 EXPECT_TRUE(new_enabled_types.Equals(sync_manager_.InitialSyncEndedTypes())); | 3084 EXPECT_TRUE(new_enabled_types.Equals(sync_manager_.InitialSyncEndedTypes())); |
| 3077 EXPECT_TRUE(disabled_types.Equals( | 3085 EXPECT_TRUE(disabled_types.Equals( |
| 3078 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); | 3086 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); |
| 3079 } | 3087 } |
| 3080 | 3088 |
| 3081 } // namespace | 3089 } // namespace |
| OLD | NEW |