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

Side by Side Diff: sync/engine/syncer_unittest.cc

Issue 14963002: sync: Report GetUpdate triggers to the server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update tests Created 7 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
OLDNEW
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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 case SyncEngineEvent::SYNC_CYCLE_BEGIN: // Fall through. 164 case SyncEngineEvent::SYNC_CYCLE_BEGIN: // Fall through.
165 case SyncEngineEvent::STATUS_CHANGED: 165 case SyncEngineEvent::STATUS_CHANGED:
166 case SyncEngineEvent::SYNC_CYCLE_ENDED: 166 case SyncEngineEvent::SYNC_CYCLE_ENDED:
167 return; 167 return;
168 default: 168 default:
169 CHECK(false) << "Handling unknown error type in unit tests!!"; 169 CHECK(false) << "Handling unknown error type in unit tests!!";
170 } 170 }
171 saw_syncer_event_ = true; 171 saw_syncer_event_ = true;
172 } 172 }
173 173
174 SyncSession* MakeSession() { 174 void SyncShareNudge() {
175 ModelSafeRoutingInfo info; 175 ModelSafeRoutingInfo info;
176 GetModelSafeRoutingInfo(&info); 176 GetModelSafeRoutingInfo(&info);
177 ModelTypeInvalidationMap invalidation_map = 177 ModelTypeInvalidationMap invalidation_map =
178 ModelSafeRoutingInfoToInvalidationMap(info, std::string()); 178 ModelSafeRoutingInfoToInvalidationMap(info, std::string());
179 sessions::SyncSourceInfo source_info(sync_pb::GetUpdatesCallerInfo::UNKNOWN, 179 sessions::SyncSourceInfo source_info(
180 invalidation_map); 180 sync_pb::GetUpdatesCallerInfo::LOCAL,
181 return new SyncSession(context_.get(), this, source_info); 181 invalidation_map);
182 } 182 // Use our dummy nudge tracker. These tests won't notice that it hasn't
183 // been tracking anything.
184 session_.reset(
185 new SyncSession(context_.get(), this, source_info, &nudge_tracker_));
183 186
184 void SyncShareNudge() {
185 session_.reset(MakeSession());
186 EXPECT_TRUE(syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END)); 187 EXPECT_TRUE(syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END));
187 } 188 }
188 189
189 void SyncShareConfigure() { 190 void SyncShareConfigure() {
190 session_.reset(MakeSession()); 191 ModelSafeRoutingInfo info;
192 GetModelSafeRoutingInfo(&info);
193 ModelTypeInvalidationMap invalidation_map =
194 ModelSafeRoutingInfoToInvalidationMap(info, std::string());
195 sessions::SyncSourceInfo source_info(
196 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION,
197 invalidation_map);
198 session_.reset(new SyncSession(context_.get(), this, source_info));
191 EXPECT_TRUE( 199 EXPECT_TRUE(
192 syncer_->SyncShare(session_.get(), DOWNLOAD_UPDATES, APPLY_UPDATES)); 200 syncer_->SyncShare(session_.get(), DOWNLOAD_UPDATES, APPLY_UPDATES));
193 } 201 }
194 202
195 virtual void SetUp() { 203 virtual void SetUp() {
196 dir_maker_.SetUp(); 204 dir_maker_.SetUp();
197 mock_server_.reset(new MockConnectionManager(directory())); 205 mock_server_.reset(new MockConnectionManager(directory()));
198 EnableDatatype(BOOKMARKS); 206 EnableDatatype(BOOKMARKS);
199 EnableDatatype(NIGORI); 207 EnableDatatype(NIGORI);
200 EnableDatatype(PREFERENCES); 208 EnableDatatype(PREFERENCES);
(...skipping 12 matching lines...) Expand all
213 221
214 context_.reset( 222 context_.reset(
215 new SyncSessionContext( 223 new SyncSessionContext(
216 mock_server_.get(), directory(), workers, 224 mock_server_.get(), directory(), workers,
217 &extensions_activity_monitor_, throttled_data_type_tracker_.get(), 225 &extensions_activity_monitor_, throttled_data_type_tracker_.get(),
218 listeners, NULL, &traffic_recorder_, 226 listeners, NULL, &traffic_recorder_,
219 true, // enable keystore encryption 227 true, // enable keystore encryption
220 "fake_invalidator_client_id")); 228 "fake_invalidator_client_id"));
221 context_->set_routing_info(routing_info); 229 context_->set_routing_info(routing_info);
222 syncer_ = new Syncer(); 230 syncer_ = new Syncer();
223 session_.reset(MakeSession());
224 231
225 syncable::ReadTransaction trans(FROM_HERE, directory()); 232 syncable::ReadTransaction trans(FROM_HERE, directory());
226 syncable::Directory::ChildHandles children; 233 syncable::Directory::ChildHandles children;
227 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); 234 directory()->GetChildHandlesById(&trans, trans.root_id(), &children);
228 ASSERT_EQ(0u, children.size()); 235 ASSERT_EQ(0u, children.size());
229 saw_syncer_event_ = false; 236 saw_syncer_event_ = false;
230 root_id_ = TestIdFactory::root(); 237 root_id_ = TestIdFactory::root();
231 parent_id_ = ids_.MakeServer("parent id"); 238 parent_id_ = ids_.MakeServer("parent id");
232 child_id_ = ids_.MakeServer("child id"); 239 child_id_ = ids_.MakeServer("child id");
233 directory()->set_store_birthday(mock_server_->store_birthday()); 240 directory()->set_store_birthday(mock_server_->store_birthday());
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 scoped_ptr<SyncSession> session_; 567 scoped_ptr<SyncSession> session_;
561 scoped_ptr<SyncSessionContext> context_; 568 scoped_ptr<SyncSessionContext> context_;
562 bool saw_syncer_event_; 569 bool saw_syncer_event_;
563 base::TimeDelta last_short_poll_interval_received_; 570 base::TimeDelta last_short_poll_interval_received_;
564 base::TimeDelta last_long_poll_interval_received_; 571 base::TimeDelta last_long_poll_interval_received_;
565 base::TimeDelta last_sessions_commit_delay_seconds_; 572 base::TimeDelta last_sessions_commit_delay_seconds_;
566 scoped_refptr<ModelSafeWorker> worker_; 573 scoped_refptr<ModelSafeWorker> worker_;
567 574
568 ModelTypeSet enabled_datatypes_; 575 ModelTypeSet enabled_datatypes_;
569 TrafficRecorder traffic_recorder_; 576 TrafficRecorder traffic_recorder_;
577 sessions::NudgeTracker nudge_tracker_;
570 578
571 DISALLOW_COPY_AND_ASSIGN(SyncerTest); 579 DISALLOW_COPY_AND_ASSIGN(SyncerTest);
572 }; 580 };
573 581
574 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { 582 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) {
575 { 583 {
576 Syncer::UnsyncedMetaHandles handles; 584 Syncer::UnsyncedMetaHandles handles;
577 { 585 {
578 syncable::ReadTransaction trans(FROM_HERE, directory()); 586 syncable::ReadTransaction trans(FROM_HERE, directory());
579 GetUnsyncedEntries(&trans, &handles); 587 GetUnsyncedEntries(&trans, &handles);
(...skipping 1655 matching lines...) Expand 10 before | Expand all | Expand 10 after
2235 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob"); 2243 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob");
2236 ASSERT_TRUE(entry.good()); 2244 ASSERT_TRUE(entry.good());
2237 entry.Put(syncable::IS_DIR, true); 2245 entry.Put(syncable::IS_DIR, true);
2238 entry.Put(syncable::IS_UNSYNCED, true); 2246 entry.Put(syncable::IS_UNSYNCED, true);
2239 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 2247 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
2240 } 2248 }
2241 2249
2242 mock_server_->SetMidCommitCallback( 2250 mock_server_->SetMidCommitCallback(
2243 base::Bind(&EntryCreatedInNewFolderTest::CreateFolderInBob, 2251 base::Bind(&EntryCreatedInNewFolderTest::CreateFolderInBob,
2244 base::Unretained(this))); 2252 base::Unretained(this)));
2245 syncer_->SyncShare(session_.get(), COMMIT, SYNCER_END); 2253 SyncShareNudge();
2246 // We loop until no unsynced handles remain, so we will commit both ids. 2254 // We loop until no unsynced handles remain, so we will commit both ids.
2247 EXPECT_EQ(2u, mock_server_->committed_ids().size()); 2255 EXPECT_EQ(2u, mock_server_->committed_ids().size());
2248 { 2256 {
2249 syncable::ReadTransaction trans(FROM_HERE, directory()); 2257 syncable::ReadTransaction trans(FROM_HERE, directory());
2250 Entry parent_entry(&trans, syncable::GET_BY_ID, 2258 Entry parent_entry(&trans, syncable::GET_BY_ID,
2251 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "bob")); 2259 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "bob"));
2252 ASSERT_TRUE(parent_entry.good()); 2260 ASSERT_TRUE(parent_entry.good());
2253 2261
2254 Id child_id = 2262 Id child_id =
2255 GetOnlyEntryWithName(&trans, parent_entry.Get(ID), "bob"); 2263 GetOnlyEntryWithName(&trans, parent_entry.Get(ID), "bob");
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
2473 entry.Put(ID, ids_.FromNumber(20)); 2481 entry.Put(ID, ids_.FromNumber(20));
2474 entry.Put(BASE_VERSION, 1); 2482 entry.Put(BASE_VERSION, 1);
2475 entry.Put(SERVER_VERSION, 1); 2483 entry.Put(SERVER_VERSION, 1);
2476 entry.Put(SERVER_PARENT_ID, ids_.FromNumber(9999)); // Bad parent. 2484 entry.Put(SERVER_PARENT_ID, ids_.FromNumber(9999)); // Bad parent.
2477 entry.Put(IS_UNSYNCED, true); 2485 entry.Put(IS_UNSYNCED, true);
2478 entry.Put(IS_UNAPPLIED_UPDATE, true); 2486 entry.Put(IS_UNAPPLIED_UPDATE, true);
2479 entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2487 entry.Put(SPECIFICS, DefaultBookmarkSpecifics());
2480 entry.Put(SERVER_SPECIFICS, DefaultBookmarkSpecifics()); 2488 entry.Put(SERVER_SPECIFICS, DefaultBookmarkSpecifics());
2481 entry.Put(IS_DEL, false); 2489 entry.Put(IS_DEL, false);
2482 } 2490 }
2483 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 2491 SyncShareNudge();
2484 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
2485 EXPECT_EQ(1, session_->status_controller().TotalNumConflictingItems()); 2492 EXPECT_EQ(1, session_->status_controller().TotalNumConflictingItems());
2486 saw_syncer_event_ = false; 2493 saw_syncer_event_ = false;
2487 } 2494 }
2488 2495
2489 // Original problem synopsis: 2496 // Original problem synopsis:
2490 // Illegal parent 2497 // Illegal parent
2491 // Unexpected error during sync if we: 2498 // Unexpected error during sync if we:
2492 // make a new folder bob 2499 // make a new folder bob
2493 // wait for sync 2500 // wait for sync
2494 // make a new folder fred 2501 // make a new folder fred
2495 // move bob into fred 2502 // move bob into fred
2496 // remove bob 2503 // remove bob
2497 // remove fred 2504 // remove fred
2498 // if no syncing occured midway, bob will have an illegal parent 2505 // if no syncing occured midway, bob will have an illegal parent
2499 TEST_F(SyncerTest, DeletingEntryInFolder) { 2506 TEST_F(SyncerTest, DeletingEntryInFolder) {
2500 // This test is a little fake. 2507 // This test is a little fake.
2501 int64 existing_metahandle; 2508 int64 existing_metahandle;
2502 { 2509 {
2503 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2510 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2504 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "existing"); 2511 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "existing");
2505 ASSERT_TRUE(entry.good()); 2512 ASSERT_TRUE(entry.good());
2506 entry.Put(IS_DIR, true); 2513 entry.Put(IS_DIR, true);
2507 entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2514 entry.Put(SPECIFICS, DefaultBookmarkSpecifics());
2508 entry.Put(IS_UNSYNCED, true); 2515 entry.Put(IS_UNSYNCED, true);
2509 existing_metahandle = entry.Get(META_HANDLE); 2516 existing_metahandle = entry.Get(META_HANDLE);
2510 } 2517 }
2511 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 2518 SyncShareNudge();
2512 { 2519 {
2513 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2520 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2514 MutableEntry newfolder(&trans, CREATE, BOOKMARKS, trans.root_id(), "new"); 2521 MutableEntry newfolder(&trans, CREATE, BOOKMARKS, trans.root_id(), "new");
2515 ASSERT_TRUE(newfolder.good()); 2522 ASSERT_TRUE(newfolder.good());
2516 newfolder.Put(IS_DIR, true); 2523 newfolder.Put(IS_DIR, true);
2517 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2524 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics());
2518 newfolder.Put(IS_UNSYNCED, true); 2525 newfolder.Put(IS_UNSYNCED, true);
2519 2526
2520 MutableEntry existing(&trans, GET_BY_HANDLE, existing_metahandle); 2527 MutableEntry existing(&trans, GET_BY_HANDLE, existing_metahandle);
2521 ASSERT_TRUE(existing.good()); 2528 ASSERT_TRUE(existing.good());
2522 existing.Put(PARENT_ID, newfolder.Get(ID)); 2529 existing.Put(PARENT_ID, newfolder.Get(ID));
2523 existing.Put(IS_UNSYNCED, true); 2530 existing.Put(IS_UNSYNCED, true);
2524 EXPECT_TRUE(existing.Get(ID).ServerKnows()); 2531 EXPECT_TRUE(existing.Get(ID).ServerKnows());
2525 2532
2526 newfolder.Put(IS_DEL, true); 2533 newfolder.Put(IS_DEL, true);
2527 existing.Put(IS_DEL, true); 2534 existing.Put(IS_DEL, true);
2528 } 2535 }
2529 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 2536 SyncShareNudge();
2530 EXPECT_EQ(0, status().num_server_conflicts()); 2537 EXPECT_EQ(0, status().num_server_conflicts());
2531 } 2538 }
2532 2539
2533 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) { 2540 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) {
2534 int64 newfolder_metahandle; 2541 int64 newfolder_metahandle;
2535 2542
2536 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, 2543 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10,
2537 foreign_cache_guid(), "-1"); 2544 foreign_cache_guid(), "-1");
2538 SyncShareNudge(); 2545 SyncShareNudge();
2539 { 2546 {
2540 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2547 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2541 MutableEntry newfolder( 2548 MutableEntry newfolder(
2542 &trans, CREATE, BOOKMARKS, ids_.FromNumber(1), "local"); 2549 &trans, CREATE, BOOKMARKS, ids_.FromNumber(1), "local");
2543 ASSERT_TRUE(newfolder.good()); 2550 ASSERT_TRUE(newfolder.good());
2544 newfolder.Put(IS_UNSYNCED, true); 2551 newfolder.Put(IS_UNSYNCED, true);
2545 newfolder.Put(IS_DIR, true); 2552 newfolder.Put(IS_DIR, true);
2546 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2553 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics());
2547 newfolder_metahandle = newfolder.Get(META_HANDLE); 2554 newfolder_metahandle = newfolder.Get(META_HANDLE);
2548 } 2555 }
2549 mock_server_->AddUpdateDirectory(1, 0, "bob", 2, 20, 2556 mock_server_->AddUpdateDirectory(1, 0, "bob", 2, 20,
2550 foreign_cache_guid(), "-1"); 2557 foreign_cache_guid(), "-1");
2551 mock_server_->SetLastUpdateDeleted(); 2558 mock_server_->SetLastUpdateDeleted();
2552 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, APPLY_UPDATES); 2559 SyncShareConfigure();
2553 { 2560 {
2554 syncable::ReadTransaction trans(FROM_HERE, directory()); 2561 syncable::ReadTransaction trans(FROM_HERE, directory());
2555 Entry entry(&trans, syncable::GET_BY_HANDLE, newfolder_metahandle); 2562 Entry entry(&trans, syncable::GET_BY_HANDLE, newfolder_metahandle);
2556 ASSERT_TRUE(entry.good()); 2563 ASSERT_TRUE(entry.good());
2557 } 2564 }
2558 } 2565 }
2559 2566
2560 TEST_F(SyncerTest, FolderSwapUpdate) { 2567 TEST_F(SyncerTest, FolderSwapUpdate) {
2561 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10, 2568 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10,
2562 foreign_cache_guid(), "-7801"); 2569 foreign_cache_guid(), "-7801");
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
3197 const int depth = 400; 3204 const int depth = 400;
3198 syncable::Id folder_id = ids_.FromNumber(1); 3205 syncable::Id folder_id = ids_.FromNumber(1);
3199 3206
3200 // First we an item in a folder in the root. However the folder won't come 3207 // First we an item in a folder in the root. However the folder won't come
3201 // till much later. 3208 // till much later.
3202 syncable::Id stuck_entry_id = TestIdFactory::FromNumber(99999); 3209 syncable::Id stuck_entry_id = TestIdFactory::FromNumber(99999);
3203 mock_server_->AddUpdateDirectory(stuck_entry_id, 3210 mock_server_->AddUpdateDirectory(stuck_entry_id,
3204 folder_id, "stuck", 1, 1, 3211 folder_id, "stuck", 1, 1,
3205 foreign_cache_guid(), "-99999"); 3212 foreign_cache_guid(), "-99999");
3206 mock_server_->SetChangesRemaining(depth - 1); 3213 mock_server_->SetChangesRemaining(depth - 1);
3207 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 3214 SyncShareNudge();
3208 3215
3209 // Buffer up a very long series of downloads. 3216 // Buffer up a very long series of downloads.
3210 // We should never be stuck (conflict resolution shouldn't 3217 // We should never be stuck (conflict resolution shouldn't
3211 // kick in so long as we're making forward progress). 3218 // kick in so long as we're making forward progress).
3212 for (int i = 0; i < depth; i++) { 3219 for (int i = 0; i < depth; i++) {
3213 mock_server_->NextUpdateBatch(); 3220 mock_server_->NextUpdateBatch();
3214 mock_server_->SetNewTimestamp(i + 1); 3221 mock_server_->SetNewTimestamp(i + 1);
3215 mock_server_->SetChangesRemaining(depth - i); 3222 mock_server_->SetChangesRemaining(depth - i);
3216 } 3223 }
3217 3224
(...skipping 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after
4792 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); 4799 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id);
4793 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); 4800 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count);
4794 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); 4801 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count);
4795 } else { 4802 } else {
4796 EXPECT_TRUE(final_monitor_records.empty()) 4803 EXPECT_TRUE(final_monitor_records.empty())
4797 << "Should not restore records after successful bookmark commit."; 4804 << "Should not restore records after successful bookmark commit.";
4798 } 4805 }
4799 } 4806 }
4800 4807
4801 } // namespace syncer 4808 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698