| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "sync/syncable/directory_unittest.h" | 5 #include "components/sync/syncable/directory_unittest.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <cstdlib> | 10 #include <cstdlib> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/test/values_test_util.h" | 16 #include "base/test/values_test_util.h" |
| 17 #include "sync/internal_api/public/base/attachment_id_proto.h" | 17 #include "components/sync/base/attachment_id_proto.h" |
| 18 #include "sync/syncable/syncable_proto_util.h" | 18 #include "components/sync/base/mock_unrecoverable_error_handler.h" |
| 19 #include "sync/syncable/syncable_util.h" | 19 #include "components/sync/syncable/syncable_proto_util.h" |
| 20 #include "sync/syncable/syncable_write_transaction.h" | 20 #include "components/sync/syncable/syncable_util.h" |
| 21 #include "sync/test/engine/test_syncable_utils.h" | 21 #include "components/sync/syncable/syncable_write_transaction.h" |
| 22 #include "sync/test/test_directory_backing_store.h" | 22 #include "components/sync/test/engine/test_syncable_utils.h" |
| 23 #include "sync/util/mock_unrecoverable_error_handler.h" | 23 #include "components/sync/test/test_directory_backing_store.h" |
| 24 | 24 |
| 25 using base::ExpectDictBooleanValue; | 25 using base::ExpectDictBooleanValue; |
| 26 using base::ExpectDictStringValue; | 26 using base::ExpectDictStringValue; |
| 27 | 27 |
| 28 namespace syncer { | 28 namespace syncer { |
| 29 | 29 |
| 30 namespace syncable { | 30 namespace syncable { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 53 ASSERT_TRUE(e->GetSpecifics().has_bookmark()); | 53 ASSERT_TRUE(e->GetSpecifics().has_bookmark()); |
| 54 ASSERT_EQ("http://demo/", e->GetSpecifics().bookmark().url()); | 54 ASSERT_EQ("http://demo/", e->GetSpecifics().bookmark().url()); |
| 55 ASSERT_EQ(std::string(bytes, bytes_length), | 55 ASSERT_EQ(std::string(bytes, bytes_length), |
| 56 e->GetSpecifics().bookmark().favicon()); | 56 e->GetSpecifics().bookmark().favicon()); |
| 57 } | 57 } |
| 58 | 58 |
| 59 } // namespace | 59 } // namespace |
| 60 | 60 |
| 61 const char SyncableDirectoryTest::kDirectoryName[] = "Foo"; | 61 const char SyncableDirectoryTest::kDirectoryName[] = "Foo"; |
| 62 | 62 |
| 63 SyncableDirectoryTest::SyncableDirectoryTest() { | 63 SyncableDirectoryTest::SyncableDirectoryTest() {} |
| 64 } | |
| 65 | 64 |
| 66 SyncableDirectoryTest::~SyncableDirectoryTest() { | 65 SyncableDirectoryTest::~SyncableDirectoryTest() {} |
| 67 } | |
| 68 | 66 |
| 69 void SyncableDirectoryTest::SetUp() { | 67 void SyncableDirectoryTest::SetUp() { |
| 70 ASSERT_TRUE(connection_.OpenInMemory()); | 68 ASSERT_TRUE(connection_.OpenInMemory()); |
| 71 ASSERT_EQ(OPENED, ReopenDirectory()); | 69 ASSERT_EQ(OPENED, ReopenDirectory()); |
| 72 } | 70 } |
| 73 | 71 |
| 74 void SyncableDirectoryTest::TearDown() { | 72 void SyncableDirectoryTest::TearDown() { |
| 75 if (dir_) | 73 if (dir_) |
| 76 dir_->SaveChanges(); | 74 dir_->SaveChanges(); |
| 77 dir_.reset(); | 75 dir_.reset(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 104 // Creates an empty entry and sets the ID field to id. | 102 // Creates an empty entry and sets the ID field to id. |
| 105 void SyncableDirectoryTest::CreateEntry(const ModelType& model_type, | 103 void SyncableDirectoryTest::CreateEntry(const ModelType& model_type, |
| 106 const std::string& entryname, | 104 const std::string& entryname, |
| 107 const int id) { | 105 const int id) { |
| 108 CreateEntry(model_type, entryname, TestIdFactory::FromNumber(id)); | 106 CreateEntry(model_type, entryname, TestIdFactory::FromNumber(id)); |
| 109 } | 107 } |
| 110 | 108 |
| 111 void SyncableDirectoryTest::CreateEntry(const ModelType& model_type, | 109 void SyncableDirectoryTest::CreateEntry(const ModelType& model_type, |
| 112 const std::string& entryname, | 110 const std::string& entryname, |
| 113 const Id& id) { | 111 const Id& id) { |
| 114 CreateEntryWithAttachmentMetadata( | 112 CreateEntryWithAttachmentMetadata(model_type, entryname, id, |
| 115 model_type, entryname, id, sync_pb::AttachmentMetadata()); | 113 sync_pb::AttachmentMetadata()); |
| 116 } | 114 } |
| 117 | 115 |
| 118 void SyncableDirectoryTest::CreateEntryWithAttachmentMetadata( | 116 void SyncableDirectoryTest::CreateEntryWithAttachmentMetadata( |
| 119 const ModelType& model_type, | 117 const ModelType& model_type, |
| 120 const std::string& entryname, | 118 const std::string& entryname, |
| 121 const Id& id, | 119 const Id& id, |
| 122 const sync_pb::AttachmentMetadata& attachment_metadata) { | 120 const sync_pb::AttachmentMetadata& attachment_metadata) { |
| 123 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); | 121 WriteTransaction wtrans(FROM_HERE, UNITTEST, dir_.get()); |
| 124 MutableEntry me(&wtrans, CREATE, model_type, wtrans.root_id(), entryname); | 122 MutableEntry me(&wtrans, CREATE, model_type, wtrans.root_id(), entryname); |
| 125 ASSERT_TRUE(me.good()); | 123 ASSERT_TRUE(me.good()); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 } | 203 } |
| 206 | 204 |
| 207 DirectoryChangeDelegate* SyncableDirectoryTest::directory_change_delegate() { | 205 DirectoryChangeDelegate* SyncableDirectoryTest::directory_change_delegate() { |
| 208 return &delegate_; | 206 return &delegate_; |
| 209 } | 207 } |
| 210 | 208 |
| 211 Encryptor* SyncableDirectoryTest::encryptor() { | 209 Encryptor* SyncableDirectoryTest::encryptor() { |
| 212 return &encryptor_; | 210 return &encryptor_; |
| 213 } | 211 } |
| 214 | 212 |
| 215 | |
| 216 TestUnrecoverableErrorHandler* | 213 TestUnrecoverableErrorHandler* |
| 217 SyncableDirectoryTest::unrecoverable_error_handler() { | 214 SyncableDirectoryTest::unrecoverable_error_handler() { |
| 218 return &handler_; | 215 return &handler_; |
| 219 } | 216 } |
| 220 | 217 |
| 221 void SyncableDirectoryTest::ValidateEntry(BaseTransaction* trans, | 218 void SyncableDirectoryTest::ValidateEntry(BaseTransaction* trans, |
| 222 int64_t id, | 219 int64_t id, |
| 223 bool check_name, | 220 bool check_name, |
| 224 const std::string& name, | 221 const std::string& name, |
| 225 int64_t base_version, | 222 int64_t base_version, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 } | 288 } |
| 292 // Fake SaveChanges() and make sure we got what we expected. | 289 // Fake SaveChanges() and make sure we got what we expected. |
| 293 { | 290 { |
| 294 Directory::SaveChangesSnapshot snapshot; | 291 Directory::SaveChangesSnapshot snapshot; |
| 295 base::AutoLock scoped_lock(dir()->kernel()->save_changes_mutex); | 292 base::AutoLock scoped_lock(dir()->kernel()->save_changes_mutex); |
| 296 dir()->TakeSnapshotForSaveChanges(&snapshot); | 293 dir()->TakeSnapshotForSaveChanges(&snapshot); |
| 297 // Make sure there's an entry for each new metahandle. Make sure all | 294 // Make sure there's an entry for each new metahandle. Make sure all |
| 298 // entries are marked dirty. | 295 // entries are marked dirty. |
| 299 ASSERT_EQ(expected_dirty_metahandles.size(), snapshot.dirty_metas.size()); | 296 ASSERT_EQ(expected_dirty_metahandles.size(), snapshot.dirty_metas.size()); |
| 300 for (EntryKernelSet::const_iterator i = snapshot.dirty_metas.begin(); | 297 for (EntryKernelSet::const_iterator i = snapshot.dirty_metas.begin(); |
| 301 i != snapshot.dirty_metas.end(); | 298 i != snapshot.dirty_metas.end(); ++i) { |
| 302 ++i) { | |
| 303 ASSERT_TRUE((*i)->is_dirty()); | 299 ASSERT_TRUE((*i)->is_dirty()); |
| 304 } | 300 } |
| 305 dir()->VacuumAfterSaveChanges(snapshot); | 301 dir()->VacuumAfterSaveChanges(snapshot); |
| 306 } | 302 } |
| 307 // Put a new value with existing transactions as well as adding new ones. | 303 // Put a new value with existing transactions as well as adding new ones. |
| 308 { | 304 { |
| 309 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 305 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 310 std::vector<int64_t> new_dirty_metahandles; | 306 std::vector<int64_t> new_dirty_metahandles; |
| 311 for (std::vector<int64_t>::const_iterator i = | 307 for (std::vector<int64_t>::const_iterator i = |
| 312 expected_dirty_metahandles.begin(); | 308 expected_dirty_metahandles.begin(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 326 } | 322 } |
| 327 // Fake SaveChanges() and make sure we got what we expected. | 323 // Fake SaveChanges() and make sure we got what we expected. |
| 328 { | 324 { |
| 329 Directory::SaveChangesSnapshot snapshot; | 325 Directory::SaveChangesSnapshot snapshot; |
| 330 base::AutoLock scoped_lock(dir()->kernel()->save_changes_mutex); | 326 base::AutoLock scoped_lock(dir()->kernel()->save_changes_mutex); |
| 331 dir()->TakeSnapshotForSaveChanges(&snapshot); | 327 dir()->TakeSnapshotForSaveChanges(&snapshot); |
| 332 // Make sure there's an entry for each new metahandle. Make sure all | 328 // Make sure there's an entry for each new metahandle. Make sure all |
| 333 // entries are marked dirty. | 329 // entries are marked dirty. |
| 334 EXPECT_EQ(expected_dirty_metahandles.size(), snapshot.dirty_metas.size()); | 330 EXPECT_EQ(expected_dirty_metahandles.size(), snapshot.dirty_metas.size()); |
| 335 for (EntryKernelSet::const_iterator i = snapshot.dirty_metas.begin(); | 331 for (EntryKernelSet::const_iterator i = snapshot.dirty_metas.begin(); |
| 336 i != snapshot.dirty_metas.end(); | 332 i != snapshot.dirty_metas.end(); ++i) { |
| 337 ++i) { | |
| 338 EXPECT_TRUE((*i)->is_dirty()); | 333 EXPECT_TRUE((*i)->is_dirty()); |
| 339 } | 334 } |
| 340 dir()->VacuumAfterSaveChanges(snapshot); | 335 dir()->VacuumAfterSaveChanges(snapshot); |
| 341 } | 336 } |
| 342 } | 337 } |
| 343 | 338 |
| 344 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsOnlyDirtyHandlesTest) { | 339 TEST_F(SyncableDirectoryTest, TakeSnapshotGetsOnlyDirtyHandlesTest) { |
| 345 const int metahandles_to_create = 100; | 340 const int metahandles_to_create = 100; |
| 346 | 341 |
| 347 // half of 2 * metahandles_to_create | 342 // half of 2 * metahandles_to_create |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 } | 412 } |
| 418 // Fake SaveChanges() and make sure we got what we expected. | 413 // Fake SaveChanges() and make sure we got what we expected. |
| 419 { | 414 { |
| 420 Directory::SaveChangesSnapshot snapshot; | 415 Directory::SaveChangesSnapshot snapshot; |
| 421 base::AutoLock scoped_lock(dir()->kernel()->save_changes_mutex); | 416 base::AutoLock scoped_lock(dir()->kernel()->save_changes_mutex); |
| 422 dir()->TakeSnapshotForSaveChanges(&snapshot); | 417 dir()->TakeSnapshotForSaveChanges(&snapshot); |
| 423 // Make sure there's an entry for each changed metahandle. Make sure all | 418 // Make sure there's an entry for each changed metahandle. Make sure all |
| 424 // entries are marked dirty. | 419 // entries are marked dirty. |
| 425 EXPECT_EQ(number_changed, snapshot.dirty_metas.size()); | 420 EXPECT_EQ(number_changed, snapshot.dirty_metas.size()); |
| 426 for (EntryKernelSet::const_iterator i = snapshot.dirty_metas.begin(); | 421 for (EntryKernelSet::const_iterator i = snapshot.dirty_metas.begin(); |
| 427 i != snapshot.dirty_metas.end(); | 422 i != snapshot.dirty_metas.end(); ++i) { |
| 428 ++i) { | |
| 429 EXPECT_TRUE((*i)->is_dirty()); | 423 EXPECT_TRUE((*i)->is_dirty()); |
| 430 } | 424 } |
| 431 dir()->VacuumAfterSaveChanges(snapshot); | 425 dir()->VacuumAfterSaveChanges(snapshot); |
| 432 } | 426 } |
| 433 } | 427 } |
| 434 | 428 |
| 435 // Test delete journals management. | 429 // Test delete journals management. |
| 436 TEST_F(SyncableDirectoryTest, ManageDeleteJournals) { | 430 TEST_F(SyncableDirectoryTest, ManageDeleteJournals) { |
| 437 sync_pb::EntitySpecifics bookmark_specifics; | 431 sync_pb::EntitySpecifics bookmark_specifics; |
| 438 AddDefaultFieldValue(BOOKMARKS, &bookmark_specifics); | 432 AddDefaultFieldValue(BOOKMARKS, &bookmark_specifics); |
| (...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 ASSERT_TRUE(item.good()); | 1050 ASSERT_TRUE(item.good()); |
| 1057 item.PutId(id_factory.NewServerId()); | 1051 item.PutId(id_factory.NewServerId()); |
| 1058 item.PutSpecifics(specifics); | 1052 item.PutSpecifics(specifics); |
| 1059 item.PutBaseVersion(1); | 1053 item.PutBaseVersion(1); |
| 1060 item.PutIsDir(false); | 1054 item.PutIsDir(false); |
| 1061 item.PutIsDel(false); | 1055 item.PutIsDel(false); |
| 1062 ASSERT_EQ(datatype, item.GetModelType()); | 1056 ASSERT_EQ(datatype, item.GetModelType()); |
| 1063 | 1057 |
| 1064 // It's critical that deletion records retain their datatype, so that | 1058 // It's critical that deletion records retain their datatype, so that |
| 1065 // they can be dispatched to the appropriate change processor. | 1059 // they can be dispatched to the appropriate change processor. |
| 1066 MutableEntry deleted_item( | 1060 MutableEntry deleted_item(&trans, CREATE, BOOKMARKS, trans.root_id(), |
| 1067 &trans, CREATE, BOOKMARKS, trans.root_id(), "Deleted Item"); | 1061 "Deleted Item"); |
| 1068 ASSERT_TRUE(item.good()); | 1062 ASSERT_TRUE(item.good()); |
| 1069 deleted_item.PutId(id_factory.NewServerId()); | 1063 deleted_item.PutId(id_factory.NewServerId()); |
| 1070 deleted_item.PutSpecifics(specifics); | 1064 deleted_item.PutSpecifics(specifics); |
| 1071 deleted_item.PutBaseVersion(1); | 1065 deleted_item.PutBaseVersion(1); |
| 1072 deleted_item.PutIsDir(false); | 1066 deleted_item.PutIsDir(false); |
| 1073 deleted_item.PutIsDel(true); | 1067 deleted_item.PutIsDel(true); |
| 1074 ASSERT_EQ(datatype, deleted_item.GetModelType()); | 1068 ASSERT_EQ(datatype, deleted_item.GetModelType()); |
| 1075 | 1069 |
| 1076 MutableEntry server_folder( | 1070 MutableEntry server_folder(&trans, CREATE_NEW_UPDATE_ITEM, |
| 1077 &trans, CREATE_NEW_UPDATE_ITEM, id_factory.NewServerId()); | 1071 id_factory.NewServerId()); |
| 1078 ASSERT_TRUE(server_folder.good()); | 1072 ASSERT_TRUE(server_folder.good()); |
| 1079 server_folder.PutServerSpecifics(specifics); | 1073 server_folder.PutServerSpecifics(specifics); |
| 1080 server_folder.PutBaseVersion(1); | 1074 server_folder.PutBaseVersion(1); |
| 1081 server_folder.PutServerIsDir(true); | 1075 server_folder.PutServerIsDir(true); |
| 1082 server_folder.PutServerIsDel(false); | 1076 server_folder.PutServerIsDel(false); |
| 1083 ASSERT_EQ(datatype, server_folder.GetServerModelType()); | 1077 ASSERT_EQ(datatype, server_folder.GetServerModelType()); |
| 1084 | 1078 |
| 1085 MutableEntry server_item( | 1079 MutableEntry server_item(&trans, CREATE_NEW_UPDATE_ITEM, |
| 1086 &trans, CREATE_NEW_UPDATE_ITEM, id_factory.NewServerId()); | 1080 id_factory.NewServerId()); |
| 1087 ASSERT_TRUE(server_item.good()); | 1081 ASSERT_TRUE(server_item.good()); |
| 1088 server_item.PutServerSpecifics(specifics); | 1082 server_item.PutServerSpecifics(specifics); |
| 1089 server_item.PutBaseVersion(1); | 1083 server_item.PutBaseVersion(1); |
| 1090 server_item.PutServerIsDir(false); | 1084 server_item.PutServerIsDir(false); |
| 1091 server_item.PutServerIsDel(false); | 1085 server_item.PutServerIsDel(false); |
| 1092 ASSERT_EQ(datatype, server_item.GetServerModelType()); | 1086 ASSERT_EQ(datatype, server_item.GetServerModelType()); |
| 1093 | 1087 |
| 1094 sync_pb::SyncEntity folder_entity; | 1088 sync_pb::SyncEntity folder_entity; |
| 1095 folder_entity.set_id_string(SyncableIdToProto(id_factory.NewServerId())); | 1089 folder_entity.set_id_string(SyncableIdToProto(id_factory.NewServerId())); |
| 1096 folder_entity.set_deleted(false); | 1090 folder_entity.set_deleted(false); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1293 Id zombie_id = id_factory.NewLocalId(); | 1287 Id zombie_id = id_factory.NewLocalId(); |
| 1294 | 1288 |
| 1295 // We're about to do some bad things. Tell the directory verification | 1289 // We're about to do some bad things. Tell the directory verification |
| 1296 // routines to look the other way. | 1290 // routines to look the other way. |
| 1297 dir()->SetInvariantCheckLevel(OFF); | 1291 dir()->SetInvariantCheckLevel(OFF); |
| 1298 | 1292 |
| 1299 { | 1293 { |
| 1300 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 1294 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 1301 | 1295 |
| 1302 // Create an uncommitted tombstone entry. | 1296 // Create an uncommitted tombstone entry. |
| 1303 MutableEntry server_knows( | 1297 MutableEntry server_knows(&trans, CREATE, BOOKMARKS, id_factory.root(), |
| 1304 &trans, CREATE, BOOKMARKS, id_factory.root(), "server_knows"); | 1298 "server_knows"); |
| 1305 server_knows.PutId(server_knows_id); | 1299 server_knows.PutId(server_knows_id); |
| 1306 server_knows.PutIsUnsynced(true); | 1300 server_knows.PutIsUnsynced(true); |
| 1307 server_knows.PutIsDel(true); | 1301 server_knows.PutIsDel(true); |
| 1308 server_knows.PutBaseVersion(5); | 1302 server_knows.PutBaseVersion(5); |
| 1309 server_knows.PutServerVersion(4); | 1303 server_knows.PutServerVersion(4); |
| 1310 | 1304 |
| 1311 // Create a valid update entry. | 1305 // Create a valid update entry. |
| 1312 MutableEntry not_is_del( | 1306 MutableEntry not_is_del(&trans, CREATE, BOOKMARKS, id_factory.root(), |
| 1313 &trans, CREATE, BOOKMARKS, id_factory.root(), "not_is_del"); | 1307 "not_is_del"); |
| 1314 not_is_del.PutId(not_is_del_id); | 1308 not_is_del.PutId(not_is_del_id); |
| 1315 not_is_del.PutIsDel(false); | 1309 not_is_del.PutIsDel(false); |
| 1316 not_is_del.PutIsUnsynced(true); | 1310 not_is_del.PutIsUnsynced(true); |
| 1317 | 1311 |
| 1318 // Create a tombstone which should never be sent to the server because the | 1312 // Create a tombstone which should never be sent to the server because the |
| 1319 // server never knew about the item's existence. | 1313 // server never knew about the item's existence. |
| 1320 // | 1314 // |
| 1321 // New clients should never put entries into this state. We work around | 1315 // New clients should never put entries into this state. We work around |
| 1322 // this by setting IS_DEL before setting IS_UNSYNCED, something which the | 1316 // this by setting IS_DEL before setting IS_UNSYNCED, something which the |
| 1323 // client should never do in practice. | 1317 // client should never do in practice. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1398 | 1392 |
| 1399 MutableEntry parent(&trans, CREATE, BOOKMARKS, id_factory.root(), "parent"); | 1393 MutableEntry parent(&trans, CREATE, BOOKMARKS, id_factory.root(), "parent"); |
| 1400 parent.PutIsDir(true); | 1394 parent.PutIsDir(true); |
| 1401 parent.PutIsUnsynced(true); | 1395 parent.PutIsUnsynced(true); |
| 1402 | 1396 |
| 1403 // The code is littered with DCHECKs that try to stop us from doing what | 1397 // The code is littered with DCHECKs that try to stop us from doing what |
| 1404 // we're about to do. Our work-around is to create a bookmark based on | 1398 // we're about to do. Our work-around is to create a bookmark based on |
| 1405 // a server update, then update its local specifics without updating its | 1399 // a server update, then update its local specifics without updating its |
| 1406 // local unique position. | 1400 // local unique position. |
| 1407 | 1401 |
| 1408 MutableEntry child( | 1402 MutableEntry child(&trans, CREATE_NEW_UPDATE_ITEM, |
| 1409 &trans, CREATE_NEW_UPDATE_ITEM, id_factory.MakeServer("child")); | 1403 id_factory.MakeServer("child")); |
| 1410 sync_pb::EntitySpecifics specifics; | 1404 sync_pb::EntitySpecifics specifics; |
| 1411 AddDefaultFieldValue(BOOKMARKS, &specifics); | 1405 AddDefaultFieldValue(BOOKMARKS, &specifics); |
| 1412 child.PutIsUnappliedUpdate(true); | 1406 child.PutIsUnappliedUpdate(true); |
| 1413 child.PutSpecifics(specifics); | 1407 child.PutSpecifics(specifics); |
| 1414 | 1408 |
| 1415 EXPECT_TRUE(child.ShouldMaintainPosition()); | 1409 EXPECT_TRUE(child.ShouldMaintainPosition()); |
| 1416 EXPECT_TRUE(!child.GetUniquePosition().IsValid()); | 1410 EXPECT_TRUE(!child.GetUniquePosition().IsValid()); |
| 1417 } | 1411 } |
| 1418 | 1412 |
| 1419 EXPECT_EQ(FAILED_DATABASE_CORRUPT, SimulateSaveAndReloadDir()); | 1413 EXPECT_EQ(FAILED_DATABASE_CORRUPT, SimulateSaveAndReloadDir()); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1696 }; | 1690 }; |
| 1697 | 1691 |
| 1698 // Stress test Directory by accessing it from several threads concurrently. | 1692 // Stress test Directory by accessing it from several threads concurrently. |
| 1699 TEST_F(SyncableDirectoryTest, StressTransactions) { | 1693 TEST_F(SyncableDirectoryTest, StressTransactions) { |
| 1700 const int kThreadCount = 7; | 1694 const int kThreadCount = 7; |
| 1701 base::PlatformThreadHandle threads[kThreadCount]; | 1695 base::PlatformThreadHandle threads[kThreadCount]; |
| 1702 std::unique_ptr<StressTransactionsDelegate> thread_delegates[kThreadCount]; | 1696 std::unique_ptr<StressTransactionsDelegate> thread_delegates[kThreadCount]; |
| 1703 | 1697 |
| 1704 for (int i = 0; i < kThreadCount; ++i) { | 1698 for (int i = 0; i < kThreadCount; ++i) { |
| 1705 thread_delegates[i].reset(new StressTransactionsDelegate(dir().get(), i)); | 1699 thread_delegates[i].reset(new StressTransactionsDelegate(dir().get(), i)); |
| 1706 ASSERT_TRUE(base::PlatformThread::Create( | 1700 ASSERT_TRUE(base::PlatformThread::Create(0, thread_delegates[i].get(), |
| 1707 0, thread_delegates[i].get(), &threads[i])); | 1701 &threads[i])); |
| 1708 } | 1702 } |
| 1709 | 1703 |
| 1710 for (int i = 0; i < kThreadCount; ++i) { | 1704 for (int i = 0; i < kThreadCount; ++i) { |
| 1711 base::PlatformThread::Join(threads[i]); | 1705 base::PlatformThread::Join(threads[i]); |
| 1712 } | 1706 } |
| 1713 } | 1707 } |
| 1714 | 1708 |
| 1715 // Verify that Directory is notifed when a MutableEntry's AttachmentMetadata | 1709 // Verify that Directory is notifed when a MutableEntry's AttachmentMetadata |
| 1716 // changes. | 1710 // changes. |
| 1717 TEST_F(SyncableDirectoryTest, MutableEntry_PutAttachmentMetadata) { | 1711 TEST_F(SyncableDirectoryTest, MutableEntry_PutAttachmentMetadata) { |
| 1718 sync_pb::AttachmentMetadata attachment_metadata; | 1712 sync_pb::AttachmentMetadata attachment_metadata; |
| 1719 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); | 1713 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); |
| 1720 sync_pb::AttachmentIdProto attachment_id_proto = | 1714 sync_pb::AttachmentIdProto attachment_id_proto = |
| 1721 syncer::CreateAttachmentIdProto(0, 0); | 1715 syncer::CreateAttachmentIdProto(0, 0); |
| 1722 *record->mutable_id() = attachment_id_proto; | 1716 *record->mutable_id() = attachment_id_proto; |
| 1723 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1717 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1724 { | 1718 { |
| 1725 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 1719 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 1726 | 1720 |
| 1727 // Create an entry with attachment metadata and see that the attachment id | 1721 // Create an entry with attachment metadata and see that the attachment id |
| 1728 // is not linked. | 1722 // is not linked. |
| 1729 MutableEntry entry( | 1723 MutableEntry entry(&trans, CREATE, PREFERENCES, trans.root_id(), |
| 1730 &trans, CREATE, PREFERENCES, trans.root_id(), "some entry"); | 1724 "some entry"); |
| 1731 entry.PutId(TestIdFactory::FromNumber(-1)); | 1725 entry.PutId(TestIdFactory::FromNumber(-1)); |
| 1732 entry.PutIsUnsynced(true); | 1726 entry.PutIsUnsynced(true); |
| 1733 | 1727 |
| 1734 Directory::Metahandles metahandles; | 1728 Directory::Metahandles metahandles; |
| 1735 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1729 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1736 dir()->GetMetahandlesByAttachmentId( | 1730 dir()->GetMetahandlesByAttachmentId(&trans, attachment_id_proto, |
| 1737 &trans, attachment_id_proto, &metahandles); | 1731 &metahandles); |
| 1738 ASSERT_TRUE(metahandles.empty()); | 1732 ASSERT_TRUE(metahandles.empty()); |
| 1739 | 1733 |
| 1740 // Now add the attachment metadata and see that Directory believes it is | 1734 // Now add the attachment metadata and see that Directory believes it is |
| 1741 // linked. | 1735 // linked. |
| 1742 entry.PutAttachmentMetadata(attachment_metadata); | 1736 entry.PutAttachmentMetadata(attachment_metadata); |
| 1743 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1737 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1744 dir()->GetMetahandlesByAttachmentId( | 1738 dir()->GetMetahandlesByAttachmentId(&trans, attachment_id_proto, |
| 1745 &trans, attachment_id_proto, &metahandles); | 1739 &metahandles); |
| 1746 ASSERT_FALSE(metahandles.empty()); | 1740 ASSERT_FALSE(metahandles.empty()); |
| 1747 ASSERT_EQ(metahandles[0], entry.GetMetahandle()); | 1741 ASSERT_EQ(metahandles[0], entry.GetMetahandle()); |
| 1748 | 1742 |
| 1749 // Clear out the attachment metadata and see that it's no longer linked. | 1743 // Clear out the attachment metadata and see that it's no longer linked. |
| 1750 sync_pb::AttachmentMetadata empty_attachment_metadata; | 1744 sync_pb::AttachmentMetadata empty_attachment_metadata; |
| 1751 entry.PutAttachmentMetadata(empty_attachment_metadata); | 1745 entry.PutAttachmentMetadata(empty_attachment_metadata); |
| 1752 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1746 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1753 dir()->GetMetahandlesByAttachmentId( | 1747 dir()->GetMetahandlesByAttachmentId(&trans, attachment_id_proto, |
| 1754 &trans, attachment_id_proto, &metahandles); | 1748 &metahandles); |
| 1755 ASSERT_TRUE(metahandles.empty()); | 1749 ASSERT_TRUE(metahandles.empty()); |
| 1756 } | 1750 } |
| 1757 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1751 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1758 } | 1752 } |
| 1759 | 1753 |
| 1760 // Verify that UpdateAttachmentId updates attachment_id and is_on_server flag. | 1754 // Verify that UpdateAttachmentId updates attachment_id and is_on_server flag. |
| 1761 TEST_F(SyncableDirectoryTest, MutableEntry_UpdateAttachmentId) { | 1755 TEST_F(SyncableDirectoryTest, MutableEntry_UpdateAttachmentId) { |
| 1762 sync_pb::AttachmentMetadata attachment_metadata; | 1756 sync_pb::AttachmentMetadata attachment_metadata; |
| 1763 sync_pb::AttachmentMetadataRecord* r1 = attachment_metadata.add_record(); | 1757 sync_pb::AttachmentMetadataRecord* r1 = attachment_metadata.add_record(); |
| 1764 sync_pb::AttachmentMetadataRecord* r2 = attachment_metadata.add_record(); | 1758 sync_pb::AttachmentMetadataRecord* r2 = attachment_metadata.add_record(); |
| 1765 *r1->mutable_id() = syncer::CreateAttachmentIdProto(0, 0); | 1759 *r1->mutable_id() = syncer::CreateAttachmentIdProto(0, 0); |
| 1766 *r2->mutable_id() = syncer::CreateAttachmentIdProto(0, 0); | 1760 *r2->mutable_id() = syncer::CreateAttachmentIdProto(0, 0); |
| 1767 sync_pb::AttachmentIdProto attachment_id_proto = r1->id(); | 1761 sync_pb::AttachmentIdProto attachment_id_proto = r1->id(); |
| 1768 | 1762 |
| 1769 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | 1763 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); |
| 1770 | 1764 |
| 1771 MutableEntry entry( | 1765 MutableEntry entry(&trans, CREATE, PREFERENCES, trans.root_id(), |
| 1772 &trans, CREATE, PREFERENCES, trans.root_id(), "some entry"); | 1766 "some entry"); |
| 1773 entry.PutId(TestIdFactory::FromNumber(-1)); | 1767 entry.PutId(TestIdFactory::FromNumber(-1)); |
| 1774 entry.PutAttachmentMetadata(attachment_metadata); | 1768 entry.PutAttachmentMetadata(attachment_metadata); |
| 1775 | 1769 |
| 1776 { | 1770 { |
| 1777 const sync_pb::AttachmentMetadata& entry_metadata = | 1771 const sync_pb::AttachmentMetadata& entry_metadata = |
| 1778 entry.GetAttachmentMetadata(); | 1772 entry.GetAttachmentMetadata(); |
| 1779 ASSERT_EQ(2, entry_metadata.record_size()); | 1773 ASSERT_EQ(2, entry_metadata.record_size()); |
| 1780 ASSERT_FALSE(entry_metadata.record(0).is_on_server()); | 1774 ASSERT_FALSE(entry_metadata.record(0).is_on_server()); |
| 1781 ASSERT_FALSE(entry_metadata.record(1).is_on_server()); | 1775 ASSERT_FALSE(entry_metadata.record(1).is_on_server()); |
| 1782 ASSERT_FALSE(entry.GetIsUnsynced()); | 1776 ASSERT_FALSE(entry.GetIsUnsynced()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1801 sync_pb::AttachmentMetadata attachment_metadata; | 1795 sync_pb::AttachmentMetadata attachment_metadata; |
| 1802 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); | 1796 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); |
| 1803 sync_pb::AttachmentIdProto attachment_id_proto = | 1797 sync_pb::AttachmentIdProto attachment_id_proto = |
| 1804 syncer::CreateAttachmentIdProto(0, 0); | 1798 syncer::CreateAttachmentIdProto(0, 0); |
| 1805 *record->mutable_id() = attachment_id_proto; | 1799 *record->mutable_id() = attachment_id_proto; |
| 1806 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1800 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1807 const Id id = TestIdFactory::FromNumber(-1); | 1801 const Id id = TestIdFactory::FromNumber(-1); |
| 1808 | 1802 |
| 1809 // Create an entry with attachment metadata and see that the attachment id | 1803 // Create an entry with attachment metadata and see that the attachment id |
| 1810 // is linked. | 1804 // is linked. |
| 1811 CreateEntryWithAttachmentMetadata( | 1805 CreateEntryWithAttachmentMetadata(PREFERENCES, "some entry", id, |
| 1812 PREFERENCES, "some entry", id, attachment_metadata); | 1806 attachment_metadata); |
| 1813 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1807 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1814 | 1808 |
| 1815 // Delete the entry and see that it's still linked because the entry hasn't | 1809 // Delete the entry and see that it's still linked because the entry hasn't |
| 1816 // yet been purged. | 1810 // yet been purged. |
| 1817 DeleteEntry(id); | 1811 DeleteEntry(id); |
| 1818 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1812 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1819 | 1813 |
| 1820 // Reload the Directory, purging the deleted entry, and see that the | 1814 // Reload the Directory, purging the deleted entry, and see that the |
| 1821 // attachment is no longer linked. | 1815 // attachment is no longer linked. |
| 1822 SimulateSaveAndReloadDir(); | 1816 SimulateSaveAndReloadDir(); |
| 1823 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1817 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1824 } | 1818 } |
| 1825 | 1819 |
| 1826 // Verify that a given attachment can be referenced by multiple entries and that | 1820 // Verify that a given attachment can be referenced by multiple entries and that |
| 1827 // any one of the references is sufficient to ensure it remains linked. | 1821 // any one of the references is sufficient to ensure it remains linked. |
| 1828 TEST_F(SyncableDirectoryTest, Directory_LastReferenceUnlinksAttachments) { | 1822 TEST_F(SyncableDirectoryTest, Directory_LastReferenceUnlinksAttachments) { |
| 1829 // Create one attachment. | 1823 // Create one attachment. |
| 1830 sync_pb::AttachmentMetadata attachment_metadata; | 1824 sync_pb::AttachmentMetadata attachment_metadata; |
| 1831 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); | 1825 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); |
| 1832 sync_pb::AttachmentIdProto attachment_id_proto = | 1826 sync_pb::AttachmentIdProto attachment_id_proto = |
| 1833 syncer::CreateAttachmentIdProto(0, 0); | 1827 syncer::CreateAttachmentIdProto(0, 0); |
| 1834 *record->mutable_id() = attachment_id_proto; | 1828 *record->mutable_id() = attachment_id_proto; |
| 1835 | 1829 |
| 1836 // Create two entries, each referencing the attachment. | 1830 // Create two entries, each referencing the attachment. |
| 1837 const Id id1 = TestIdFactory::FromNumber(-1); | 1831 const Id id1 = TestIdFactory::FromNumber(-1); |
| 1838 const Id id2 = TestIdFactory::FromNumber(-2); | 1832 const Id id2 = TestIdFactory::FromNumber(-2); |
| 1839 CreateEntryWithAttachmentMetadata( | 1833 CreateEntryWithAttachmentMetadata(PREFERENCES, "some entry", id1, |
| 1840 PREFERENCES, "some entry", id1, attachment_metadata); | 1834 attachment_metadata); |
| 1841 CreateEntryWithAttachmentMetadata( | 1835 CreateEntryWithAttachmentMetadata(PREFERENCES, "some other entry", id2, |
| 1842 PREFERENCES, "some other entry", id2, attachment_metadata); | 1836 attachment_metadata); |
| 1843 | 1837 |
| 1844 // See that the attachment is considered linked. | 1838 // See that the attachment is considered linked. |
| 1845 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1839 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1846 | 1840 |
| 1847 // Delete the first entry, reload the Directory, see that the attachment is | 1841 // Delete the first entry, reload the Directory, see that the attachment is |
| 1848 // still linked. | 1842 // still linked. |
| 1849 DeleteEntry(id1); | 1843 DeleteEntry(id1); |
| 1850 SimulateSaveAndReloadDir(); | 1844 SimulateSaveAndReloadDir(); |
| 1851 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1845 ASSERT_TRUE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1852 | 1846 |
| 1853 // Delete the second entry, reload the Directory, see that the attachment is | 1847 // Delete the second entry, reload the Directory, see that the attachment is |
| 1854 // no loner linked. | 1848 // no loner linked. |
| 1855 DeleteEntry(id2); | 1849 DeleteEntry(id2); |
| 1856 SimulateSaveAndReloadDir(); | 1850 SimulateSaveAndReloadDir(); |
| 1857 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1851 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
| 1858 } | 1852 } |
| 1859 | 1853 |
| 1860 TEST_F(SyncableDirectoryTest, Directory_GetAttachmentIdsToUpload) { | 1854 TEST_F(SyncableDirectoryTest, Directory_GetAttachmentIdsToUpload) { |
| 1861 // Create one attachment, referenced by two entries. | 1855 // Create one attachment, referenced by two entries. |
| 1862 AttachmentId attachment_id = AttachmentId::Create(0, 0); | 1856 AttachmentId attachment_id = AttachmentId::Create(0, 0); |
| 1863 sync_pb::AttachmentIdProto attachment_id_proto = attachment_id.GetProto(); | 1857 sync_pb::AttachmentIdProto attachment_id_proto = attachment_id.GetProto(); |
| 1864 sync_pb::AttachmentMetadata attachment_metadata; | 1858 sync_pb::AttachmentMetadata attachment_metadata; |
| 1865 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); | 1859 sync_pb::AttachmentMetadataRecord* record = attachment_metadata.add_record(); |
| 1866 *record->mutable_id() = attachment_id_proto; | 1860 *record->mutable_id() = attachment_id_proto; |
| 1867 const Id id1 = TestIdFactory::FromNumber(-1); | 1861 const Id id1 = TestIdFactory::FromNumber(-1); |
| 1868 const Id id2 = TestIdFactory::FromNumber(-2); | 1862 const Id id2 = TestIdFactory::FromNumber(-2); |
| 1869 CreateEntryWithAttachmentMetadata( | 1863 CreateEntryWithAttachmentMetadata(PREFERENCES, "some entry", id1, |
| 1870 PREFERENCES, "some entry", id1, attachment_metadata); | 1864 attachment_metadata); |
| 1871 CreateEntryWithAttachmentMetadata( | 1865 CreateEntryWithAttachmentMetadata(PREFERENCES, "some other entry", id2, |
| 1872 PREFERENCES, "some other entry", id2, attachment_metadata); | 1866 attachment_metadata); |
| 1873 | 1867 |
| 1874 // See that Directory reports that this attachment is not on the server. | 1868 // See that Directory reports that this attachment is not on the server. |
| 1875 AttachmentIdList ids; | 1869 AttachmentIdList ids; |
| 1876 { | 1870 { |
| 1877 ReadTransaction trans(FROM_HERE, dir().get()); | 1871 ReadTransaction trans(FROM_HERE, dir().get()); |
| 1878 dir()->GetAttachmentIdsToUpload(&trans, PREFERENCES, &ids); | 1872 dir()->GetAttachmentIdsToUpload(&trans, PREFERENCES, &ids); |
| 1879 } | 1873 } |
| 1880 ASSERT_EQ(1U, ids.size()); | 1874 ASSERT_EQ(1U, ids.size()); |
| 1881 ASSERT_EQ(attachment_id, *ids.begin()); | 1875 ASSERT_EQ(attachment_id, *ids.begin()); |
| 1882 | 1876 |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2131 EXPECT_FALSE(dir()->InitialSyncEndedForType(&trans, PREFERENCES)); | 2125 EXPECT_FALSE(dir()->InitialSyncEndedForType(&trans, PREFERENCES)); |
| 2132 | 2126 |
| 2133 // Mark as complete and verify. | 2127 // Mark as complete and verify. |
| 2134 dir()->MarkInitialSyncEndedForType(&trans, PREFERENCES); | 2128 dir()->MarkInitialSyncEndedForType(&trans, PREFERENCES); |
| 2135 EXPECT_TRUE(dir()->InitialSyncEndedForType(&trans, PREFERENCES)); | 2129 EXPECT_TRUE(dir()->InitialSyncEndedForType(&trans, PREFERENCES)); |
| 2136 } | 2130 } |
| 2137 | 2131 |
| 2138 } // namespace syncable | 2132 } // namespace syncable |
| 2139 | 2133 |
| 2140 } // namespace syncer | 2134 } // namespace syncer |
| OLD | NEW |