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 "sync/syncable/directory_unittest.h" |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "base/test/values_test_util.h" | 8 #include "base/test/values_test_util.h" |
9 #include "sync/internal_api/public/base/attachment_id_proto.h" | 9 #include "sync/internal_api/public/base/attachment_id_proto.h" |
10 #include "sync/syncable/syncable_proto_util.h" | 10 #include "sync/syncable/syncable_proto_util.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // performance benefits of not writing to disk. | 74 // performance benefits of not writing to disk. |
75 dir_.reset( | 75 dir_.reset( |
76 new Directory(new TestDirectoryBackingStore(kDirectoryName, &connection_), | 76 new Directory(new TestDirectoryBackingStore(kDirectoryName, &connection_), |
77 &handler_, | 77 &handler_, |
78 NULL, | 78 NULL, |
79 NULL, | 79 NULL, |
80 NULL)); | 80 NULL)); |
81 | 81 |
82 DirOpenResult open_result = | 82 DirOpenResult open_result = |
83 dir_->Open(kDirectoryName, &delegate_, NullTransactionObserver()); | 83 dir_->Open(kDirectoryName, &delegate_, NullTransactionObserver()); |
84 | |
85 if (open_result != OPENED) { | |
86 dir_.reset(); | |
87 } | |
88 | |
89 return open_result; | 84 return open_result; |
90 } | 85 } |
91 | 86 |
92 // Creates an empty entry and sets the ID field to a default one. | 87 // Creates an empty entry and sets the ID field to a default one. |
93 void SyncableDirectoryTest::CreateEntry(const ModelType& model_type, | 88 void SyncableDirectoryTest::CreateEntry(const ModelType& model_type, |
94 const std::string& entryname) { | 89 const std::string& entryname) { |
95 CreateEntry(model_type, entryname, TestIdFactory::FromNumber(-99)); | 90 CreateEntry(model_type, entryname, TestIdFactory::FromNumber(-99)); |
96 } | 91 } |
97 | 92 |
98 // Creates an empty entry and sets the ID field to id. | 93 // Creates an empty entry and sets the ID field to id. |
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 | 1214 |
1220 { | 1215 { |
1221 ReadTransaction trans(FROM_HERE, dir().get()); | 1216 ReadTransaction trans(FROM_HERE, dir().get()); |
1222 | 1217 |
1223 Entry null_ordinal_child(&trans, GET_BY_ID, null_child_id); | 1218 Entry null_ordinal_child(&trans, GET_BY_ID, null_child_id); |
1224 EXPECT_TRUE(null_pos.Equals(null_ordinal_child.GetUniquePosition())); | 1219 EXPECT_TRUE(null_pos.Equals(null_ordinal_child.GetUniquePosition())); |
1225 EXPECT_TRUE(null_pos.Equals(null_ordinal_child.GetServerUniquePosition())); | 1220 EXPECT_TRUE(null_pos.Equals(null_ordinal_child.GetServerUniquePosition())); |
1226 } | 1221 } |
1227 } | 1222 } |
1228 | 1223 |
1229 // Any item with BOOKMARKS in their local specifics should have a valid local | |
1230 // unique position. If there is an item in the loaded DB that does not match | |
1231 // this criteria, we consider the whole DB to be corrupt. | |
1232 TEST_F(SyncableDirectoryTest, BadPositionCountsAsCorruption) { | |
1233 TestIdFactory id_factory; | |
1234 | |
1235 { | |
1236 WriteTransaction trans(FROM_HERE, UNITTEST, dir().get()); | |
1237 | |
1238 MutableEntry parent(&trans, CREATE, BOOKMARKS, id_factory.root(), "parent"); | |
1239 parent.PutIsDir(true); | |
1240 parent.PutIsUnsynced(true); | |
1241 | |
1242 // The code is littered with DCHECKs that try to stop us from doing what | |
1243 // we're about to do. Our work-around is to create a bookmark based on | |
1244 // a server update, then update its local specifics without updating its | |
1245 // local unique position. | |
1246 | |
1247 MutableEntry child( | |
1248 &trans, CREATE_NEW_UPDATE_ITEM, id_factory.MakeServer("child")); | |
1249 sync_pb::EntitySpecifics specifics; | |
1250 AddDefaultFieldValue(BOOKMARKS, &specifics); | |
1251 child.PutIsUnappliedUpdate(true); | |
1252 child.PutSpecifics(specifics); | |
1253 | |
1254 EXPECT_TRUE(child.ShouldMaintainPosition()); | |
1255 EXPECT_TRUE(!child.GetUniquePosition().IsValid()); | |
1256 } | |
1257 | |
1258 EXPECT_EQ(FAILED_DATABASE_CORRUPT, SimulateSaveAndReloadDir()); | |
1259 } | |
1260 | |
1261 TEST_F(SyncableDirectoryTest, General) { | 1224 TEST_F(SyncableDirectoryTest, General) { |
1262 int64 written_metahandle; | 1225 int64 written_metahandle; |
1263 const Id id = TestIdFactory::FromNumber(99); | 1226 const Id id = TestIdFactory::FromNumber(99); |
1264 std::string name = "Jeff"; | 1227 std::string name = "Jeff"; |
1265 // Test simple read operations on an empty DB. | 1228 // Test simple read operations on an empty DB. |
1266 { | 1229 { |
1267 ReadTransaction rtrans(FROM_HERE, dir().get()); | 1230 ReadTransaction rtrans(FROM_HERE, dir().get()); |
1268 Entry e(&rtrans, GET_BY_ID, id); | 1231 Entry e(&rtrans, GET_BY_ID, id); |
1269 ASSERT_FALSE(e.good()); // Hasn't been written yet. | 1232 ASSERT_FALSE(e.good()); // Hasn't been written yet. |
1270 | 1233 |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1671 // Delete the second entry, reload the Directory, see that the attachment is | 1634 // Delete the second entry, reload the Directory, see that the attachment is |
1672 // no loner linked. | 1635 // no loner linked. |
1673 DeleteEntry(id2); | 1636 DeleteEntry(id2); |
1674 SimulateSaveAndReloadDir(); | 1637 SimulateSaveAndReloadDir(); |
1675 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); | 1638 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); |
1676 } | 1639 } |
1677 | 1640 |
1678 } // namespace syncable | 1641 } // namespace syncable |
1679 | 1642 |
1680 } // namespace syncer | 1643 } // namespace syncer |
OLD | NEW |