OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 syncdb_.manager(), this, listeners)); | 191 syncdb_.manager(), this, listeners)); |
192 context_->set_account_name(syncdb_.name()); | 192 context_->set_account_name(syncdb_.name()); |
193 ASSERT_FALSE(context_->resolver()); | 193 ASSERT_FALSE(context_->resolver()); |
194 syncer_ = new Syncer(); | 194 syncer_ = new Syncer(); |
195 session_.reset(MakeSession()); | 195 session_.reset(MakeSession()); |
196 | 196 |
197 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 197 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
198 CHECK(dir.good()); | 198 CHECK(dir.good()); |
199 ReadTransaction trans(dir, __FILE__, __LINE__); | 199 ReadTransaction trans(dir, __FILE__, __LINE__); |
200 syncable::Directory::ChildHandles children; | 200 syncable::Directory::ChildHandles children; |
201 dir->GetChildHandles(&trans, trans.root_id(), &children); | 201 dir->GetChildHandlesById(&trans, trans.root_id(), &children); |
202 ASSERT_TRUE(0 == children.size()); | 202 ASSERT_TRUE(0 == children.size()); |
203 saw_syncer_event_ = false; | 203 saw_syncer_event_ = false; |
204 root_id_ = TestIdFactory::root(); | 204 root_id_ = TestIdFactory::root(); |
205 parent_id_ = ids_.MakeServer("parent id"); | 205 parent_id_ = ids_.MakeServer("parent id"); |
206 child_id_ = ids_.MakeServer("child id"); | 206 child_id_ = ids_.MakeServer("child id"); |
207 } | 207 } |
208 | 208 |
209 virtual void TearDown() { | 209 virtual void TearDown() { |
210 mock_server_.reset(); | 210 mock_server_.reset(); |
211 delete syncer_; | 211 delete syncer_; |
(...skipping 1669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1881 child.Put(syncable::ID, child_id_); | 1881 child.Put(syncable::ID, child_id_); |
1882 child.Put(syncable::BASE_VERSION, 10); | 1882 child.Put(syncable::BASE_VERSION, 10); |
1883 WriteTestDataToEntry(&wtrans, &child); | 1883 WriteTestDataToEntry(&wtrans, &child); |
1884 } | 1884 } |
1885 mock_server_->AddUpdateBookmark(child_id_, parent_id_, "Pete2.htm", 11, 10); | 1885 mock_server_->AddUpdateBookmark(child_id_, parent_id_, "Pete2.htm", 11, 10); |
1886 mock_server_->set_conflict_all_commits(true); | 1886 mock_server_->set_conflict_all_commits(true); |
1887 LoopSyncShare(); | 1887 LoopSyncShare(); |
1888 syncable::Directory::ChildHandles children; | 1888 syncable::Directory::ChildHandles children; |
1889 { | 1889 { |
1890 ReadTransaction trans(dir, __FILE__, __LINE__); | 1890 ReadTransaction trans(dir, __FILE__, __LINE__); |
1891 dir->GetChildHandles(&trans, parent_id_, &children); | 1891 dir->GetChildHandlesById(&trans, parent_id_, &children); |
1892 // We expect the conflict resolver to preserve the local entry. | 1892 // We expect the conflict resolver to preserve the local entry. |
1893 Entry child(&trans, syncable::GET_BY_ID, child_id_); | 1893 Entry child(&trans, syncable::GET_BY_ID, child_id_); |
1894 ASSERT_TRUE(child.good()); | 1894 ASSERT_TRUE(child.good()); |
1895 EXPECT_TRUE(child.Get(syncable::IS_UNSYNCED)); | 1895 EXPECT_TRUE(child.Get(syncable::IS_UNSYNCED)); |
1896 EXPECT_FALSE(child.Get(syncable::IS_UNAPPLIED_UPDATE)); | 1896 EXPECT_FALSE(child.Get(syncable::IS_UNAPPLIED_UPDATE)); |
1897 EXPECT_TRUE(child.Get(SPECIFICS).HasExtension(sync_pb::bookmark)); | 1897 EXPECT_TRUE(child.Get(SPECIFICS).HasExtension(sync_pb::bookmark)); |
1898 EXPECT_EQ("Pete.htm", child.Get(NON_UNIQUE_NAME)); | 1898 EXPECT_EQ("Pete.htm", child.Get(NON_UNIQUE_NAME)); |
1899 VerifyTestBookmarkDataInEntry(&child); | 1899 VerifyTestBookmarkDataInEntry(&child); |
1900 } | 1900 } |
1901 | 1901 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1975 } | 1975 } |
1976 mock_server_->AddUpdateDirectory(parent_id, root_id_, "Folder", 10, 10); | 1976 mock_server_->AddUpdateDirectory(parent_id, root_id_, "Folder", 10, 10); |
1977 mock_server_->AddUpdateBookmark(child_id, parent_id, "test.htm", 10, 10); | 1977 mock_server_->AddUpdateBookmark(child_id, parent_id, "test.htm", 10, 10); |
1978 mock_server_->set_conflict_all_commits(true); | 1978 mock_server_->set_conflict_all_commits(true); |
1979 SyncShareAsDelegate(); | 1979 SyncShareAsDelegate(); |
1980 SyncShareAsDelegate(); | 1980 SyncShareAsDelegate(); |
1981 SyncShareAsDelegate(); | 1981 SyncShareAsDelegate(); |
1982 { | 1982 { |
1983 ReadTransaction trans(dir, __FILE__, __LINE__); | 1983 ReadTransaction trans(dir, __FILE__, __LINE__); |
1984 Directory::ChildHandles children; | 1984 Directory::ChildHandles children; |
1985 dir->GetChildHandles(&trans, root_id_, &children); | 1985 dir->GetChildHandlesById(&trans, root_id_, &children); |
1986 EXPECT_TRUE(1 == children.size()); | 1986 EXPECT_TRUE(1 == children.size()); |
1987 dir->GetChildHandles(&trans, parent_id, &children); | 1987 dir->GetChildHandlesById(&trans, parent_id, &children); |
1988 EXPECT_TRUE(1 == children.size()); | 1988 EXPECT_TRUE(1 == children.size()); |
1989 Directory::UnappliedUpdateMetaHandles unapplied; | 1989 Directory::UnappliedUpdateMetaHandles unapplied; |
1990 dir->GetUnappliedUpdateMetaHandles(&trans, &unapplied); | 1990 dir->GetUnappliedUpdateMetaHandles(&trans, &unapplied); |
1991 EXPECT_TRUE(0 == unapplied.size()); | 1991 EXPECT_TRUE(0 == unapplied.size()); |
1992 syncable::Directory::UnsyncedMetaHandles unsynced; | 1992 syncable::Directory::UnsyncedMetaHandles unsynced; |
1993 dir->GetUnsyncedMetaHandles(&trans, &unsynced); | 1993 dir->GetUnsyncedMetaHandles(&trans, &unsynced); |
1994 EXPECT_TRUE(0 == unsynced.size()); | 1994 EXPECT_TRUE(0 == unsynced.size()); |
1995 saw_syncer_event_ = false; | 1995 saw_syncer_event_ = false; |
1996 } | 1996 } |
1997 } | 1997 } |
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3111 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 3111 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
3112 ASSERT_TRUE(dir.good()); | 3112 ASSERT_TRUE(dir.good()); |
3113 | 3113 |
3114 const syncable::Id susan_id = TestIdFactory::FromNumber(susan_int_id_); | 3114 const syncable::Id susan_id = TestIdFactory::FromNumber(susan_int_id_); |
3115 ASSERT_GT(countdown_till_delete_, 0); | 3115 ASSERT_GT(countdown_till_delete_, 0); |
3116 if (0 != --countdown_till_delete_) | 3116 if (0 != --countdown_till_delete_) |
3117 return; | 3117 return; |
3118 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); | 3118 WriteTransaction trans(dir, UNITTEST, __FILE__, __LINE__); |
3119 MutableEntry susan(&trans, GET_BY_ID, susan_id); | 3119 MutableEntry susan(&trans, GET_BY_ID, susan_id); |
3120 Directory::ChildHandles children; | 3120 Directory::ChildHandles children; |
3121 dir->GetChildHandles(&trans, susan.Get(ID), &children); | 3121 dir->GetChildHandlesById(&trans, susan.Get(ID), &children); |
3122 ASSERT_TRUE(0 == children.size()); | 3122 ASSERT_TRUE(0 == children.size()); |
3123 susan.Put(IS_DEL, true); | 3123 susan.Put(IS_DEL, true); |
3124 susan.Put(IS_UNSYNCED, true); | 3124 susan.Put(IS_UNSYNCED, true); |
3125 } | 3125 } |
3126 | 3126 |
3127 protected: | 3127 protected: |
3128 int countdown_till_delete_; | 3128 int countdown_till_delete_; |
3129 }; | 3129 }; |
3130 | 3130 |
3131 TEST_F(SusanDeletingTest, | 3131 TEST_F(SusanDeletingTest, |
(...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4281 ASSERT_TRUE(ids_.FromNumber(4) == tag2.Get(ID)); | 4281 ASSERT_TRUE(ids_.FromNumber(4) == tag2.Get(ID)); |
4282 EXPECT_FALSE(tag2.Get(IS_DEL)); | 4282 EXPECT_FALSE(tag2.Get(IS_DEL)); |
4283 EXPECT_FALSE(tag2.Get(IS_UNAPPLIED_UPDATE)); | 4283 EXPECT_FALSE(tag2.Get(IS_UNAPPLIED_UPDATE)); |
4284 EXPECT_FALSE(tag2.Get(IS_UNSYNCED)); | 4284 EXPECT_FALSE(tag2.Get(IS_UNSYNCED)); |
4285 EXPECT_EQ("Four", tag2.Get(NON_UNIQUE_NAME)); | 4285 EXPECT_EQ("Four", tag2.Get(NON_UNIQUE_NAME)); |
4286 EXPECT_EQ(11, tag2.Get(BASE_VERSION)); | 4286 EXPECT_EQ(11, tag2.Get(BASE_VERSION)); |
4287 EXPECT_EQ("tag2", tag2.Get(UNIQUE_CLIENT_TAG)); | 4287 EXPECT_EQ("tag2", tag2.Get(UNIQUE_CLIENT_TAG)); |
4288 tag2_metahandle = tag2.Get(META_HANDLE); | 4288 tag2_metahandle = tag2.Get(META_HANDLE); |
4289 | 4289 |
4290 syncable::Directory::ChildHandles children; | 4290 syncable::Directory::ChildHandles children; |
4291 dir->GetChildHandles(&trans, trans.root_id(), &children); | 4291 dir->GetChildHandlesById(&trans, trans.root_id(), &children); |
4292 ASSERT_EQ(2U, children.size()); | 4292 ASSERT_EQ(2U, children.size()); |
4293 } | 4293 } |
4294 | 4294 |
4295 mock_server_->AddUpdateBookmark(2, 0, "Two", 12, 120); | 4295 mock_server_->AddUpdateBookmark(2, 0, "Two", 12, 120); |
4296 mock_server_->SetLastUpdateClientTag("tag1"); | 4296 mock_server_->SetLastUpdateClientTag("tag1"); |
4297 mock_server_->AddUpdateBookmark(3, 0, "Three", 13, 130); | 4297 mock_server_->AddUpdateBookmark(3, 0, "Three", 13, 130); |
4298 mock_server_->SetLastUpdateClientTag("tag2"); | 4298 mock_server_->SetLastUpdateClientTag("tag2"); |
4299 SyncShareAsDelegate(); | 4299 SyncShareAsDelegate(); |
4300 | 4300 |
4301 { | 4301 { |
(...skipping 19 matching lines...) Expand all Loading... |
4321 << "ID 3 should be kept, since it was less than ID 4."; | 4321 << "ID 3 should be kept, since it was less than ID 4."; |
4322 EXPECT_FALSE(tag2.Get(IS_DEL)); | 4322 EXPECT_FALSE(tag2.Get(IS_DEL)); |
4323 EXPECT_FALSE(tag2.Get(IS_UNAPPLIED_UPDATE)); | 4323 EXPECT_FALSE(tag2.Get(IS_UNAPPLIED_UPDATE)); |
4324 EXPECT_FALSE(tag2.Get(IS_UNSYNCED)); | 4324 EXPECT_FALSE(tag2.Get(IS_UNSYNCED)); |
4325 EXPECT_EQ("Three", tag2.Get(NON_UNIQUE_NAME)); | 4325 EXPECT_EQ("Three", tag2.Get(NON_UNIQUE_NAME)); |
4326 EXPECT_EQ(13, tag2.Get(BASE_VERSION)); | 4326 EXPECT_EQ(13, tag2.Get(BASE_VERSION)); |
4327 EXPECT_EQ("tag2", tag2.Get(UNIQUE_CLIENT_TAG)); | 4327 EXPECT_EQ("tag2", tag2.Get(UNIQUE_CLIENT_TAG)); |
4328 EXPECT_EQ(tag2_metahandle, tag2.Get(META_HANDLE)); | 4328 EXPECT_EQ(tag2_metahandle, tag2.Get(META_HANDLE)); |
4329 | 4329 |
4330 syncable::Directory::ChildHandles children; | 4330 syncable::Directory::ChildHandles children; |
4331 dir->GetChildHandles(&trans, trans.root_id(), &children); | 4331 dir->GetChildHandlesById(&trans, trans.root_id(), &children); |
4332 ASSERT_EQ(2U, children.size()); | 4332 ASSERT_EQ(2U, children.size()); |
4333 } | 4333 } |
4334 } | 4334 } |
4335 | 4335 |
4336 TEST_F(SyncerTest, ClientTagClashWithinBatchOfUpdates) { | 4336 TEST_F(SyncerTest, ClientTagClashWithinBatchOfUpdates) { |
4337 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 4337 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
4338 EXPECT_TRUE(dir.good()); | 4338 EXPECT_TRUE(dir.good()); |
4339 | 4339 |
4340 // This test is written assuming that ID comparison | 4340 // This test is written assuming that ID comparison |
4341 // will work out in a particular way. | 4341 // will work out in a particular way. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4403 EXPECT_TRUE(tag_c.Get(ID).ServerKnows()); | 4403 EXPECT_TRUE(tag_c.Get(ID).ServerKnows()); |
4404 EXPECT_EQ(ids_.FromNumber(201), tag_c.Get(ID)); | 4404 EXPECT_EQ(ids_.FromNumber(201), tag_c.Get(ID)); |
4405 EXPECT_FALSE(tag_c.Get(IS_DEL)); | 4405 EXPECT_FALSE(tag_c.Get(IS_DEL)); |
4406 EXPECT_FALSE(tag_c.Get(IS_UNAPPLIED_UPDATE)); | 4406 EXPECT_FALSE(tag_c.Get(IS_UNAPPLIED_UPDATE)); |
4407 EXPECT_FALSE(tag_c.Get(IS_UNSYNCED)); | 4407 EXPECT_FALSE(tag_c.Get(IS_UNSYNCED)); |
4408 EXPECT_EQ("Four C", tag_c.Get(NON_UNIQUE_NAME)); | 4408 EXPECT_EQ("Four C", tag_c.Get(NON_UNIQUE_NAME)); |
4409 EXPECT_EQ(21, tag_c.Get(BASE_VERSION)); | 4409 EXPECT_EQ(21, tag_c.Get(BASE_VERSION)); |
4410 EXPECT_EQ("tag c", tag_c.Get(UNIQUE_CLIENT_TAG)); | 4410 EXPECT_EQ("tag c", tag_c.Get(UNIQUE_CLIENT_TAG)); |
4411 | 4411 |
4412 syncable::Directory::ChildHandles children; | 4412 syncable::Directory::ChildHandles children; |
4413 dir->GetChildHandles(&trans, trans.root_id(), &children); | 4413 dir->GetChildHandlesById(&trans, trans.root_id(), &children); |
4414 ASSERT_EQ(3U, children.size()); | 4414 ASSERT_EQ(3U, children.size()); |
4415 } | 4415 } |
4416 } | 4416 } |
4417 | 4417 |
4418 TEST_F(SyncerTest, UniqueServerTagUpdates) { | 4418 TEST_F(SyncerTest, UniqueServerTagUpdates) { |
4419 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); | 4419 ScopedDirLookup dir(syncdb_.manager(), syncdb_.name()); |
4420 EXPECT_TRUE(dir.good()); | 4420 EXPECT_TRUE(dir.good()); |
4421 // As a hurdle, introduce an item whose name is the same as the tag value | 4421 // As a hurdle, introduce an item whose name is the same as the tag value |
4422 // we'll use later. | 4422 // we'll use later. |
4423 int64 hurdle_handle = CreateUnsyncedDirectory("bob", "id_bob"); | 4423 int64 hurdle_handle = CreateUnsyncedDirectory("bob", "id_bob"); |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5177 Add(low_id_); | 5177 Add(low_id_); |
5178 Add(high_id_); | 5178 Add(high_id_); |
5179 SyncShareAsDelegate(); | 5179 SyncShareAsDelegate(); |
5180 ExpectLocalOrderIsByServerId(); | 5180 ExpectLocalOrderIsByServerId(); |
5181 } | 5181 } |
5182 | 5182 |
5183 const SyncerTest::CommitOrderingTest | 5183 const SyncerTest::CommitOrderingTest |
5184 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; | 5184 SyncerTest::CommitOrderingTest::LAST_COMMIT_ITEM = {-1, TestIdFactory::root()}; |
5185 | 5185 |
5186 } // namespace browser_sync | 5186 } // namespace browser_sync |
OLD | NEW |