Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: sync/syncable/directory_unittest.cc

Issue 283143002: sync: Improve handling of bad UniquePos (retry) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/syncable/directory_backing_store.cc ('k') | sync/syncable/syncable_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
84 return open_result; 89 return open_result;
85 } 90 }
86 91
87 // Creates an empty entry and sets the ID field to a default one. 92 // Creates an empty entry and sets the ID field to a default one.
88 void SyncableDirectoryTest::CreateEntry(const ModelType& model_type, 93 void SyncableDirectoryTest::CreateEntry(const ModelType& model_type,
89 const std::string& entryname) { 94 const std::string& entryname) {
90 CreateEntry(model_type, entryname, TestIdFactory::FromNumber(-99)); 95 CreateEntry(model_type, entryname, TestIdFactory::FromNumber(-99));
91 } 96 }
92 97
93 // Creates an empty entry and sets the ID field to id. 98 // Creates an empty entry and sets the ID field to id.
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 1219
1215 { 1220 {
1216 ReadTransaction trans(FROM_HERE, dir().get()); 1221 ReadTransaction trans(FROM_HERE, dir().get());
1217 1222
1218 Entry null_ordinal_child(&trans, GET_BY_ID, null_child_id); 1223 Entry null_ordinal_child(&trans, GET_BY_ID, null_child_id);
1219 EXPECT_TRUE(null_pos.Equals(null_ordinal_child.GetUniquePosition())); 1224 EXPECT_TRUE(null_pos.Equals(null_ordinal_child.GetUniquePosition()));
1220 EXPECT_TRUE(null_pos.Equals(null_ordinal_child.GetServerUniquePosition())); 1225 EXPECT_TRUE(null_pos.Equals(null_ordinal_child.GetServerUniquePosition()));
1221 } 1226 }
1222 } 1227 }
1223 1228
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
1224 TEST_F(SyncableDirectoryTest, General) { 1261 TEST_F(SyncableDirectoryTest, General) {
1225 int64 written_metahandle; 1262 int64 written_metahandle;
1226 const Id id = TestIdFactory::FromNumber(99); 1263 const Id id = TestIdFactory::FromNumber(99);
1227 std::string name = "Jeff"; 1264 std::string name = "Jeff";
1228 // Test simple read operations on an empty DB. 1265 // Test simple read operations on an empty DB.
1229 { 1266 {
1230 ReadTransaction rtrans(FROM_HERE, dir().get()); 1267 ReadTransaction rtrans(FROM_HERE, dir().get());
1231 Entry e(&rtrans, GET_BY_ID, id); 1268 Entry e(&rtrans, GET_BY_ID, id);
1232 ASSERT_FALSE(e.good()); // Hasn't been written yet. 1269 ASSERT_FALSE(e.good()); // Hasn't been written yet.
1233 1270
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 // Delete the second entry, reload the Directory, see that the attachment is 1671 // Delete the second entry, reload the Directory, see that the attachment is
1635 // no loner linked. 1672 // no loner linked.
1636 DeleteEntry(id2); 1673 DeleteEntry(id2);
1637 SimulateSaveAndReloadDir(); 1674 SimulateSaveAndReloadDir();
1638 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto)); 1675 ASSERT_FALSE(dir()->IsAttachmentLinked(attachment_id_proto));
1639 } 1676 }
1640 1677
1641 } // namespace syncable 1678 } // namespace syncable
1642 1679
1643 } // namespace syncer 1680 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/syncable/directory_backing_store.cc ('k') | sync/syncable/syncable_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698