OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 // Syncer unit tests. Unfortunately a lot of these tests | 5 // Syncer unit tests. Unfortunately a lot of these tests |
6 // are outdated and need to be reworked and updated. | 6 // are outdated and need to be reworked and updated. |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <limits> | 9 #include <limits> |
10 #include <list> | 10 #include <list> |
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 EXPECT_EQ(2u, delete_journal->GetDeleteJournalSize(&rt)); | 1254 EXPECT_EQ(2u, delete_journal->GetDeleteJournalSize(&rt)); |
1255 syncable::EntryKernelSet journal_entries; | 1255 syncable::EntryKernelSet journal_entries; |
1256 directory()->delete_journal()->GetDeleteJournals(&rt, BOOKMARKS, | 1256 directory()->delete_journal()->GetDeleteJournals(&rt, BOOKMARKS, |
1257 &journal_entries); | 1257 &journal_entries); |
1258 EXPECT_EQ(parent_id_, (*journal_entries.begin())->ref(syncable::ID)); | 1258 EXPECT_EQ(parent_id_, (*journal_entries.begin())->ref(syncable::ID)); |
1259 EXPECT_EQ(child_id_, (*journal_entries.rbegin())->ref(syncable::ID)); | 1259 EXPECT_EQ(child_id_, (*journal_entries.rbegin())->ref(syncable::ID)); |
1260 } | 1260 } |
1261 } | 1261 } |
1262 | 1262 |
1263 TEST_F(SyncerTest, ResetVersions) { | 1263 TEST_F(SyncerTest, ResetVersions) { |
1264 // Download the top level pref node and some pref items. | 1264 // Download some pref items. |
1265 mock_server_->AddUpdateDirectory( | 1265 mock_server_->AddUpdatePref("id1", "", "tag1", 20, 20); |
1266 parent_id_, root_id_, "prefs", 1, 10, std::string(), std::string()); | 1266 mock_server_->AddUpdatePref("id2", "", "tag2", 30, 30); |
1267 mock_server_->SetLastUpdateServerTag(ModelTypeToRootTag(PREFERENCES)); | 1267 mock_server_->AddUpdatePref("id3", "", "tag3", 40, 40); |
1268 mock_server_->AddUpdatePref("id1", parent_id_.GetServerId(), "tag1", 20, 20); | |
1269 mock_server_->AddUpdatePref("id2", parent_id_.GetServerId(), "tag2", 30, 30); | |
1270 mock_server_->AddUpdatePref("id3", parent_id_.GetServerId(), "tag3", 40, 40); | |
1271 SyncShareNudge(); | 1268 SyncShareNudge(); |
1272 | 1269 |
1273 { | 1270 { |
1274 // Modify one of the preferences locally, mark another one as unapplied, | 1271 // Modify one of the preferences locally, mark another one as unapplied, |
1275 // and create another unsynced preference. | 1272 // and create another unsynced preference. |
1276 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1273 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1277 MutableEntry entry(&wtrans, GET_BY_CLIENT_TAG, "tag1"); | 1274 MutableEntry entry(&wtrans, GET_BY_CLIENT_TAG, "tag1"); |
1278 entry.PutIsUnsynced(true); | 1275 entry.PutIsUnsynced(true); |
1279 | 1276 |
1280 MutableEntry entry2(&wtrans, GET_BY_CLIENT_TAG, "tag2"); | 1277 MutableEntry entry2(&wtrans, GET_BY_CLIENT_TAG, "tag2"); |
1281 entry2.PutIsUnappliedUpdate(true); | 1278 entry2.PutIsUnappliedUpdate(true); |
1282 | 1279 |
1283 MutableEntry entry4(&wtrans, CREATE, PREFERENCES, parent_id_, "name"); | 1280 MutableEntry entry4(&wtrans, CREATE, PREFERENCES, "name"); |
1284 entry4.PutUniqueClientTag("tag4"); | 1281 entry4.PutUniqueClientTag("tag4"); |
1285 entry4.PutIsUnsynced(true); | 1282 entry4.PutIsUnsynced(true); |
1286 } | 1283 } |
1287 | 1284 |
1288 { | 1285 { |
1289 // Reset the versions. | 1286 // Reset the versions. |
1290 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 1287 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
1291 ASSERT_TRUE(directory()->ResetVersionsForType(&wtrans, PREFERENCES)); | 1288 ASSERT_TRUE(directory()->ResetVersionsForType(&wtrans, PREFERENCES)); |
1292 } | 1289 } |
1293 | 1290 |
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2479 SyncShareNudge(); | 2476 SyncShareNudge(); |
2480 { | 2477 { |
2481 syncable::ReadTransaction trans(FROM_HERE, directory()); | 2478 syncable::ReadTransaction trans(FROM_HERE, directory()); |
2482 Entry entry(&trans, syncable::GET_BY_ID, id); | 2479 Entry entry(&trans, syncable::GET_BY_ID, id); |
2483 ASSERT_TRUE(entry.good()); | 2480 ASSERT_TRUE(entry.good()); |
2484 EXPECT_TRUE(entry.GetMtime()== test_time); | 2481 EXPECT_TRUE(entry.GetMtime()== test_time); |
2485 } | 2482 } |
2486 } | 2483 } |
2487 | 2484 |
2488 TEST_F(SyncerTest, ParentAndChildBothMatch) { | 2485 TEST_F(SyncerTest, ParentAndChildBothMatch) { |
| 2486 // Disable PREFERENCES which is enabled at the setup step to avoid |
| 2487 // auto-creating |
| 2488 // PREFERENCES root folder and failing the test below that verifies the number |
| 2489 // of children at the root. |
| 2490 DisableDatatype(PREFERENCES); |
| 2491 |
2489 const FullModelTypeSet all_types = FullModelTypeSet::All(); | 2492 const FullModelTypeSet all_types = FullModelTypeSet::All(); |
2490 syncable::Id parent_id = ids_.NewServerId(); | 2493 syncable::Id parent_id = ids_.NewServerId(); |
2491 syncable::Id child_id = ids_.NewServerId(); | 2494 syncable::Id child_id = ids_.NewServerId(); |
2492 syncable::Id parent_local_id; | 2495 syncable::Id parent_local_id; |
2493 syncable::Id child_local_id; | 2496 syncable::Id child_local_id; |
2494 | 2497 |
2495 | |
2496 { | 2498 { |
2497 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); | 2499 WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); |
2498 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, root_id_, "Folder"); | 2500 MutableEntry parent(&wtrans, CREATE, BOOKMARKS, root_id_, "Folder"); |
2499 ASSERT_TRUE(parent.good()); | 2501 ASSERT_TRUE(parent.good()); |
2500 parent_local_id = parent.GetId(); | 2502 parent_local_id = parent.GetId(); |
2501 parent.PutIsDir(true); | 2503 parent.PutIsDir(true); |
2502 parent.PutIsUnsynced(true); | 2504 parent.PutIsUnsynced(true); |
2503 parent.PutId(parent_id); | 2505 parent.PutId(parent_id); |
2504 parent.PutBaseVersion(1); | 2506 parent.PutBaseVersion(1); |
2505 parent.PutSpecifics(DefaultBookmarkSpecifics()); | 2507 parent.PutSpecifics(DefaultBookmarkSpecifics()); |
(...skipping 1573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4079 } | 4081 } |
4080 } | 4082 } |
4081 | 4083 |
4082 TEST_F(SyncerTest, ClientTagUpdateClashesWithLocalEntry) { | 4084 TEST_F(SyncerTest, ClientTagUpdateClashesWithLocalEntry) { |
4083 // This test is written assuming that ID comparison | 4085 // This test is written assuming that ID comparison |
4084 // will work out in a particular way. | 4086 // will work out in a particular way. |
4085 EXPECT_TRUE(ids_.FromNumber(1) < ids_.FromNumber(2)); | 4087 EXPECT_TRUE(ids_.FromNumber(1) < ids_.FromNumber(2)); |
4086 EXPECT_TRUE(ids_.FromNumber(3) < ids_.FromNumber(4)); | 4088 EXPECT_TRUE(ids_.FromNumber(3) < ids_.FromNumber(4)); |
4087 | 4089 |
4088 syncable::Id id1 = TestIdFactory::MakeServer("1"); | 4090 syncable::Id id1 = TestIdFactory::MakeServer("1"); |
4089 mock_server_->AddUpdatePref(id1.GetServerId(), ids_.root().GetServerId(), | 4091 mock_server_->AddUpdatePref(id1.GetServerId(), "", "tag1", 10, 100); |
4090 "tag1", 10, 100); | |
4091 | 4092 |
4092 syncable::Id id4 = TestIdFactory::MakeServer("4"); | 4093 syncable::Id id4 = TestIdFactory::MakeServer("4"); |
4093 mock_server_->AddUpdatePref(id4.GetServerId(), ids_.root().GetServerId(), | 4094 mock_server_->AddUpdatePref(id4.GetServerId(), "", "tag2", 11, 110); |
4094 "tag2", 11, 110); | |
4095 | 4095 |
4096 mock_server_->set_conflict_all_commits(true); | 4096 mock_server_->set_conflict_all_commits(true); |
4097 | 4097 |
4098 SyncShareNudge(); | 4098 SyncShareNudge(); |
4099 int64 tag1_metahandle = syncable::kInvalidMetaHandle; | 4099 int64 tag1_metahandle = syncable::kInvalidMetaHandle; |
4100 int64 tag2_metahandle = syncable::kInvalidMetaHandle; | 4100 int64 tag2_metahandle = syncable::kInvalidMetaHandle; |
4101 // This should cause client tag overwrite. | 4101 // This should cause client tag overwrite. |
4102 { | 4102 { |
4103 syncable::ReadTransaction trans(FROM_HERE, directory()); | 4103 syncable::ReadTransaction trans(FROM_HERE, directory()); |
4104 | 4104 |
(...skipping 12 matching lines...) Expand all Loading... |
4117 ASSERT_TRUE(tag2.good()); | 4117 ASSERT_TRUE(tag2.good()); |
4118 ASSERT_TRUE(tag2.GetId().ServerKnows()); | 4118 ASSERT_TRUE(tag2.GetId().ServerKnows()); |
4119 ASSERT_TRUE(id4 == tag2.GetId()); | 4119 ASSERT_TRUE(id4 == tag2.GetId()); |
4120 EXPECT_FALSE(tag2.GetIsDel()); | 4120 EXPECT_FALSE(tag2.GetIsDel()); |
4121 EXPECT_FALSE(tag2.GetIsUnappliedUpdate()); | 4121 EXPECT_FALSE(tag2.GetIsUnappliedUpdate()); |
4122 EXPECT_FALSE(tag2.GetIsUnsynced()); | 4122 EXPECT_FALSE(tag2.GetIsUnsynced()); |
4123 EXPECT_EQ(11, tag2.GetBaseVersion()); | 4123 EXPECT_EQ(11, tag2.GetBaseVersion()); |
4124 EXPECT_EQ("tag2", tag2.GetUniqueClientTag()); | 4124 EXPECT_EQ("tag2", tag2.GetUniqueClientTag()); |
4125 tag2_metahandle = tag2.GetMetahandle(); | 4125 tag2_metahandle = tag2.GetMetahandle(); |
4126 | 4126 |
| 4127 // Preferences type root should have been created by the updates above. |
| 4128 Entry pref_root(&trans, GET_TYPE_ROOT, PREFERENCES); |
| 4129 ASSERT_TRUE(pref_root.good()); |
| 4130 |
4127 syncable::Directory::Metahandles children; | 4131 syncable::Directory::Metahandles children; |
4128 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); | 4132 directory()->GetChildHandlesById(&trans, pref_root.GetId(), &children); |
4129 ASSERT_EQ(2U, children.size()); | 4133 ASSERT_EQ(2U, children.size()); |
4130 } | 4134 } |
4131 | 4135 |
4132 syncable::Id id2 = TestIdFactory::MakeServer("2"); | 4136 syncable::Id id2 = TestIdFactory::MakeServer("2"); |
4133 mock_server_->AddUpdatePref(id2.GetServerId(), ids_.root().GetServerId(), | 4137 mock_server_->AddUpdatePref(id2.GetServerId(), "", "tag1", 12, 120); |
4134 "tag1", 12, 120); | |
4135 syncable::Id id3 = TestIdFactory::MakeServer("3"); | 4138 syncable::Id id3 = TestIdFactory::MakeServer("3"); |
4136 mock_server_->AddUpdatePref(id3.GetServerId(), ids_.root().GetServerId(), | 4139 mock_server_->AddUpdatePref(id3.GetServerId(), "", "tag2", 13, 130); |
4137 "tag2", 13, 130); | |
4138 SyncShareNudge(); | 4140 SyncShareNudge(); |
4139 | 4141 |
4140 { | 4142 { |
4141 syncable::ReadTransaction trans(FROM_HERE, directory()); | 4143 syncable::ReadTransaction trans(FROM_HERE, directory()); |
4142 | 4144 |
4143 Entry tag1(&trans, GET_BY_CLIENT_TAG, "tag1"); | 4145 Entry tag1(&trans, GET_BY_CLIENT_TAG, "tag1"); |
4144 ASSERT_TRUE(tag1.good()); | 4146 ASSERT_TRUE(tag1.good()); |
4145 ASSERT_TRUE(tag1.GetId().ServerKnows()); | 4147 ASSERT_TRUE(tag1.GetId().ServerKnows()); |
4146 ASSERT_EQ(id1, tag1.GetId()) | 4148 ASSERT_EQ(id1, tag1.GetId()) |
4147 << "ID 1 should be kept, since it was less than ID 2."; | 4149 << "ID 1 should be kept, since it was less than ID 2."; |
4148 EXPECT_FALSE(tag1.GetIsDel()); | 4150 EXPECT_FALSE(tag1.GetIsDel()); |
4149 EXPECT_FALSE(tag1.GetIsUnappliedUpdate()); | 4151 EXPECT_FALSE(tag1.GetIsUnappliedUpdate()); |
4150 EXPECT_FALSE(tag1.GetIsUnsynced()); | 4152 EXPECT_FALSE(tag1.GetIsUnsynced()); |
4151 EXPECT_EQ(10, tag1.GetBaseVersion()); | 4153 EXPECT_EQ(10, tag1.GetBaseVersion()); |
4152 EXPECT_EQ("tag1", tag1.GetUniqueClientTag()); | 4154 EXPECT_EQ("tag1", tag1.GetUniqueClientTag()); |
4153 EXPECT_EQ(tag1_metahandle, tag1.GetMetahandle()); | 4155 EXPECT_EQ(tag1_metahandle, tag1.GetMetahandle()); |
4154 | 4156 |
4155 Entry tag2(&trans, GET_BY_CLIENT_TAG, "tag2"); | 4157 Entry tag2(&trans, GET_BY_CLIENT_TAG, "tag2"); |
4156 ASSERT_TRUE(tag2.good()); | 4158 ASSERT_TRUE(tag2.good()); |
4157 ASSERT_TRUE(tag2.GetId().ServerKnows()); | 4159 ASSERT_TRUE(tag2.GetId().ServerKnows()); |
4158 ASSERT_EQ(id3, tag2.GetId()) | 4160 ASSERT_EQ(id3, tag2.GetId()) |
4159 << "ID 3 should be kept, since it was less than ID 4."; | 4161 << "ID 3 should be kept, since it was less than ID 4."; |
4160 EXPECT_FALSE(tag2.GetIsDel()); | 4162 EXPECT_FALSE(tag2.GetIsDel()); |
4161 EXPECT_FALSE(tag2.GetIsUnappliedUpdate()); | 4163 EXPECT_FALSE(tag2.GetIsUnappliedUpdate()); |
4162 EXPECT_FALSE(tag2.GetIsUnsynced()); | 4164 EXPECT_FALSE(tag2.GetIsUnsynced()); |
4163 EXPECT_EQ(13, tag2.GetBaseVersion()); | 4165 EXPECT_EQ(13, tag2.GetBaseVersion()); |
4164 EXPECT_EQ("tag2", tag2.GetUniqueClientTag()); | 4166 EXPECT_EQ("tag2", tag2.GetUniqueClientTag()); |
4165 EXPECT_EQ(tag2_metahandle, tag2.GetMetahandle()); | 4167 EXPECT_EQ(tag2_metahandle, tag2.GetMetahandle()); |
4166 | 4168 |
| 4169 // Preferences type root should have been created by the updates above. |
| 4170 Entry pref_root(&trans, GET_TYPE_ROOT, PREFERENCES); |
| 4171 ASSERT_TRUE(pref_root.good()); |
| 4172 |
4167 syncable::Directory::Metahandles children; | 4173 syncable::Directory::Metahandles children; |
4168 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); | 4174 directory()->GetChildHandlesById(&trans, pref_root.GetId(), &children); |
4169 ASSERT_EQ(2U, children.size()); | 4175 ASSERT_EQ(2U, children.size()); |
4170 } | 4176 } |
4171 } | 4177 } |
4172 | 4178 |
4173 TEST_F(SyncerTest, ClientTagClashWithinBatchOfUpdates) { | 4179 TEST_F(SyncerTest, ClientTagClashWithinBatchOfUpdates) { |
4174 // This test is written assuming that ID comparison | 4180 // This test is written assuming that ID comparison |
4175 // will work out in a particular way. | 4181 // will work out in a particular way. |
4176 EXPECT_TRUE(ids_.FromNumber(1) < ids_.FromNumber(4)); | 4182 EXPECT_TRUE(ids_.FromNumber(1) < ids_.FromNumber(4)); |
4177 EXPECT_TRUE(ids_.FromNumber(201) < ids_.FromNumber(205)); | 4183 EXPECT_TRUE(ids_.FromNumber(201) < ids_.FromNumber(205)); |
4178 | 4184 |
4179 // Least ID: winner. | 4185 // Least ID: winner. |
4180 mock_server_->AddUpdatePref(ids_.FromNumber(1).GetServerId(), | 4186 mock_server_->AddUpdatePref(ids_.FromNumber(1).GetServerId(), "", "tag a", 1, |
4181 ids_.root().GetServerId(), "tag a", 1, 10); | 4187 10); |
4182 mock_server_->AddUpdatePref(ids_.FromNumber(2).GetServerId(), | 4188 mock_server_->AddUpdatePref(ids_.FromNumber(2).GetServerId(), "", "tag a", 11, |
4183 ids_.root().GetServerId(), "tag a", 11, 110); | 4189 110); |
4184 mock_server_->AddUpdatePref(ids_.FromNumber(3).GetServerId(), | 4190 mock_server_->AddUpdatePref(ids_.FromNumber(3).GetServerId(), "", "tag a", 12, |
4185 ids_.root().GetServerId(), "tag a", 12, 120); | 4191 120); |
4186 mock_server_->AddUpdatePref(ids_.FromNumber(4).GetServerId(), | 4192 mock_server_->AddUpdatePref(ids_.FromNumber(4).GetServerId(), "", "tag a", 13, |
4187 ids_.root().GetServerId(), "tag a", 13, 130); | 4193 130); |
| 4194 mock_server_->AddUpdatePref(ids_.FromNumber(105).GetServerId(), "", "tag b", |
| 4195 14, 140); |
| 4196 mock_server_->AddUpdatePref(ids_.FromNumber(102).GetServerId(), "", "tag b", |
| 4197 15, 150); |
| 4198 // Least ID: winner. |
| 4199 mock_server_->AddUpdatePref(ids_.FromNumber(101).GetServerId(), "", "tag b", |
| 4200 16, 160); |
| 4201 mock_server_->AddUpdatePref(ids_.FromNumber(104).GetServerId(), "", "tag b", |
| 4202 17, 170); |
4188 | 4203 |
4189 mock_server_->AddUpdatePref(ids_.FromNumber(105).GetServerId(), | 4204 mock_server_->AddUpdatePref(ids_.FromNumber(205).GetServerId(), "", "tag c", |
4190 ids_.root().GetServerId(), "tag b", 14, 140); | 4205 18, 180); |
4191 mock_server_->AddUpdatePref(ids_.FromNumber(102).GetServerId(), | 4206 mock_server_->AddUpdatePref(ids_.FromNumber(202).GetServerId(), "", "tag c", |
4192 ids_.root().GetServerId(), "tag b", 15, 150); | 4207 19, 190); |
| 4208 mock_server_->AddUpdatePref(ids_.FromNumber(204).GetServerId(), "", "tag c", |
| 4209 20, 200); |
4193 // Least ID: winner. | 4210 // Least ID: winner. |
4194 mock_server_->AddUpdatePref(ids_.FromNumber(101).GetServerId(), | 4211 mock_server_->AddUpdatePref(ids_.FromNumber(201).GetServerId(), "", "tag c", |
4195 ids_.root().GetServerId(), "tag b", 16, 160); | 4212 21, 210); |
4196 mock_server_->AddUpdatePref(ids_.FromNumber(104).GetServerId(), | |
4197 ids_.root().GetServerId(), "tag b", 17, 170); | |
4198 | |
4199 mock_server_->AddUpdatePref(ids_.FromNumber(205).GetServerId(), | |
4200 ids_.root().GetServerId(), "tag c", 18, 180); | |
4201 mock_server_->AddUpdatePref(ids_.FromNumber(202).GetServerId(), | |
4202 ids_.root().GetServerId(), "tag c", 19, 190); | |
4203 mock_server_->AddUpdatePref(ids_.FromNumber(204).GetServerId(), | |
4204 ids_.root().GetServerId(), "tag c", 20, 200); | |
4205 // Least ID: winner. | |
4206 mock_server_->AddUpdatePref(ids_.FromNumber(201).GetServerId(), | |
4207 ids_.root().GetServerId(), "tag c", 21, 210); | |
4208 | 4213 |
4209 mock_server_->set_conflict_all_commits(true); | 4214 mock_server_->set_conflict_all_commits(true); |
4210 | 4215 |
4211 SyncShareNudge(); | 4216 SyncShareNudge(); |
4212 // This should cause client tag overwrite. | 4217 // This should cause client tag overwrite. |
4213 { | 4218 { |
4214 syncable::ReadTransaction trans(FROM_HERE, directory()); | 4219 syncable::ReadTransaction trans(FROM_HERE, directory()); |
4215 | 4220 |
4216 Entry tag_a(&trans, GET_BY_CLIENT_TAG, "tag a"); | 4221 Entry tag_a(&trans, GET_BY_CLIENT_TAG, "tag a"); |
4217 ASSERT_TRUE(tag_a.good()); | 4222 ASSERT_TRUE(tag_a.good()); |
(...skipping 18 matching lines...) Expand all Loading... |
4236 Entry tag_c(&trans, GET_BY_CLIENT_TAG, "tag c"); | 4241 Entry tag_c(&trans, GET_BY_CLIENT_TAG, "tag c"); |
4237 ASSERT_TRUE(tag_c.good()); | 4242 ASSERT_TRUE(tag_c.good()); |
4238 EXPECT_TRUE(tag_c.GetId().ServerKnows()); | 4243 EXPECT_TRUE(tag_c.GetId().ServerKnows()); |
4239 EXPECT_EQ(ids_.FromNumber(201), tag_c.GetId()); | 4244 EXPECT_EQ(ids_.FromNumber(201), tag_c.GetId()); |
4240 EXPECT_FALSE(tag_c.GetIsDel()); | 4245 EXPECT_FALSE(tag_c.GetIsDel()); |
4241 EXPECT_FALSE(tag_c.GetIsUnappliedUpdate()); | 4246 EXPECT_FALSE(tag_c.GetIsUnappliedUpdate()); |
4242 EXPECT_FALSE(tag_c.GetIsUnsynced()); | 4247 EXPECT_FALSE(tag_c.GetIsUnsynced()); |
4243 EXPECT_EQ(21, tag_c.GetBaseVersion()); | 4248 EXPECT_EQ(21, tag_c.GetBaseVersion()); |
4244 EXPECT_EQ("tag c", tag_c.GetUniqueClientTag()); | 4249 EXPECT_EQ("tag c", tag_c.GetUniqueClientTag()); |
4245 | 4250 |
| 4251 // Preferences type root should have been created by the updates above. |
| 4252 Entry pref_root(&trans, GET_TYPE_ROOT, PREFERENCES); |
| 4253 ASSERT_TRUE(pref_root.good()); |
| 4254 |
| 4255 // Verify that we have exactly 3 tagged nodes under the type root. |
4246 syncable::Directory::Metahandles children; | 4256 syncable::Directory::Metahandles children; |
4247 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); | 4257 directory()->GetChildHandlesById(&trans, pref_root.GetId(), &children); |
4248 ASSERT_EQ(3U, children.size()); | 4258 ASSERT_EQ(3U, children.size()); |
4249 } | 4259 } |
4250 } | 4260 } |
4251 | 4261 |
| 4262 // This verifies transition to implicit permanent folders. |
| 4263 TEST_F(SyncerTest, EntryWithParentIdUpdatedWithEntryWithoutParentId) { |
| 4264 // Make sure SPECIFICS root exists so that we can get its parent ID. |
| 4265 mock_server_->AddUpdateSpecifics(1, 0, "Folder", 10, 10, true, 1, |
| 4266 DefaultPreferencesSpecifics()); |
| 4267 mock_server_->SetLastUpdateServerTag(ModelTypeToRootTag(PREFERENCES)); |
| 4268 SyncShareNudge(); |
| 4269 |
| 4270 Id pref_root_id; |
| 4271 { |
| 4272 // Preferences type root should have been created by the update above. |
| 4273 // We need it in order to get its ID. |
| 4274 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 4275 Entry pref_root(&trans, GET_TYPE_ROOT, PREFERENCES); |
| 4276 ASSERT_TRUE(pref_root.good()); |
| 4277 pref_root_id = pref_root.GetId(); |
| 4278 } |
| 4279 |
| 4280 // Add a preference item with explicit parent ID. |
| 4281 mock_server_->AddUpdatePref(ids_.FromNumber(2).GetServerId(), |
| 4282 ids_.FromNumber(1).GetServerId(), "tag", 1, 10); |
| 4283 |
| 4284 SyncShareNudge(); |
| 4285 |
| 4286 { |
| 4287 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 4288 Entry pref_entry(&trans, GET_BY_CLIENT_TAG, "tag"); |
| 4289 ASSERT_TRUE(pref_entry.good()); |
| 4290 ASSERT_EQ(pref_root_id, pref_entry.GetParentId()); |
| 4291 } |
| 4292 |
| 4293 // Make another update where the same item get updated, this time |
| 4294 // with implicit parent ID. |
| 4295 mock_server_->AddUpdatePref(ids_.FromNumber(2).GetServerId(), "", "tag", 2, |
| 4296 20); |
| 4297 |
| 4298 SyncShareNudge(); |
| 4299 |
| 4300 { |
| 4301 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 4302 Entry pref_entry(&trans, GET_BY_CLIENT_TAG, "tag"); |
| 4303 ASSERT_TRUE(pref_entry.good()); |
| 4304 ASSERT_TRUE(pref_entry.GetParentId().IsNull()); |
| 4305 |
| 4306 // Verify that there is still one node under the type root. |
| 4307 syncable::Directory::Metahandles children; |
| 4308 directory()->GetChildHandlesById(&trans, pref_root_id, &children); |
| 4309 ASSERT_EQ(1U, children.size()); |
| 4310 } |
| 4311 } |
| 4312 |
4252 TEST_F(SyncerTest, UniqueServerTagUpdates) { | 4313 TEST_F(SyncerTest, UniqueServerTagUpdates) { |
4253 // As a hurdle, introduce an item whose name is the same as the tag value | 4314 // As a hurdle, introduce an item whose name is the same as the tag value |
4254 // we'll use later. | 4315 // we'll use later. |
4255 int64 hurdle_handle = CreateUnsyncedDirectory("bob", "id_bob"); | 4316 int64 hurdle_handle = CreateUnsyncedDirectory("bob", "id_bob"); |
4256 { | 4317 { |
4257 syncable::ReadTransaction trans(FROM_HERE, directory()); | 4318 syncable::ReadTransaction trans(FROM_HERE, directory()); |
4258 Entry hurdle(&trans, GET_BY_HANDLE, hurdle_handle); | 4319 Entry hurdle(&trans, GET_BY_HANDLE, hurdle_handle); |
4259 ASSERT_TRUE(hurdle.good()); | 4320 ASSERT_TRUE(hurdle.good()); |
4260 ASSERT_TRUE(!hurdle.GetIsDel()); | 4321 ASSERT_TRUE(!hurdle.GetIsDel()); |
4261 ASSERT_TRUE(hurdle.GetUniqueServerTag().empty()); | 4322 ASSERT_TRUE(hurdle.GetUniqueServerTag().empty()); |
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5284 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); | 5345 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); |
5285 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); | 5346 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); |
5286 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); | 5347 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); |
5287 } else { | 5348 } else { |
5288 EXPECT_TRUE(final_monitor_records.empty()) | 5349 EXPECT_TRUE(final_monitor_records.empty()) |
5289 << "Should not restore records after successful bookmark commit."; | 5350 << "Should not restore records after successful bookmark commit."; |
5290 } | 5351 } |
5291 } | 5352 } |
5292 | 5353 |
5293 } // namespace syncer | 5354 } // namespace syncer |
OLD | NEW |