Chromium Code Reviews| Index: chrome/browser/sync/engine/syncer_thread_unittest.cc |
| =================================================================== |
| --- chrome/browser/sync/engine/syncer_thread_unittest.cc (revision 71618) |
| +++ chrome/browser/sync/engine/syncer_thread_unittest.cc (working copy) |
| @@ -33,6 +33,7 @@ |
| using sessions::SyncSessionContext; |
| using sessions::SyncSessionSnapshot; |
| using sessions::SyncerStatus; |
| +using sessions::SyncSourceInfo; |
| typedef testing::Test SyncerThreadTest; |
| typedef SyncerThread::WaitInterval WaitInterval; |
| @@ -169,6 +170,47 @@ |
| syncer_thread()->SetSyncerShortPollInterval(poll_interval); |
| } |
| + // Compare a provided SyncSouceInfo::ModelTypeMap to the pending nudge info |
| + // stored in the SyncerThread vault. |
| + bool CompareNudgeTypesToVault(const SyncSourceInfo::ModelTypeMap& lhs) { |
| + const SyncSourceInfo::ModelTypeMap& vault_nudge_types = |
| + syncer_thread()->vault_.pending_nudge_types_; |
| + for (size_t i = syncable::FIRST_REAL_MODEL_TYPE; |
|
akalin
2011/01/21 19:50:09
I'm pretty sure a std::map already has operator==
Nicolas Zea
2011/01/21 21:57:44
Done.
|
| + i < syncable::MODEL_TYPE_COUNT; |
| + ++i) { |
| + syncable::ModelType type = syncable::ModelTypeFromInt(i); |
| + SyncSourceInfo::ModelTypeMap::const_iterator payload = lhs.find(type); |
| + if (payload != lhs.end()) { |
| + if (vault_nudge_types.count(type) == 0 || |
| + payload->second != vault_nudge_types.find(type)->second) { |
| + return false; |
| + } |
| + } else if (vault_nudge_types.count(type) > 0) { |
| + return false; |
| + } |
| + } |
| + return true; |
| + } |
| + |
| + // Compare a provided ModelTypeBitset to the pending nudge info stored in the |
| + // SyncerThread vault. |
| + bool CompareNudgeTypesBitSetToVault(const syncable::ModelTypeBitSet& lhs) { |
|
akalin
2011/01/21 19:50:09
If you write the utility f'n to compare ModelTypeB
Nicolas Zea
2011/01/21 21:57:44
Done.
|
| + const SyncSourceInfo::ModelTypeMap& vault_nudge_types = |
| + syncer_thread()->vault_.pending_nudge_types_; |
| + for (size_t i = syncable::FIRST_REAL_MODEL_TYPE; |
| + i < syncable::MODEL_TYPE_COUNT; |
| + ++i) { |
| + syncable::ModelType type = syncable::ModelTypeFromInt(i); |
| + if (lhs[i] && vault_nudge_types.count(type) == 0) { |
| + return false; |
| + } else if (!lhs[i] && vault_nudge_types.count(type) > 0) { |
| + return false; |
| + } |
| + } |
| + return true; |
| + } |
| + |
| + |
| private: |
| virtual void OnSyncEngineEvent(const SyncEngineEvent& event) { |
| @@ -468,7 +510,6 @@ |
| } |
| { |
| - |
| // Now try with unsynced local items. |
| context->set_last_snapshot(SessionSnapshotForTest(0, 1)); |
| bool continue_sync_cycle_param = false; |
| @@ -512,7 +553,6 @@ |
| // Regression for exponential backoff reset when the syncer is nudged. |
| { |
| - |
| context->set_last_snapshot(SessionSnapshotForTest(0, 1)); |
| bool continue_sync_cycle_param = false; |
| @@ -732,7 +772,7 @@ |
| syncer_thread()->NudgeSyncerWithDataTypes(5, |
| SyncerThread::kUnknown, |
| model_types); |
| - EXPECT_EQ(model_types, syncer_thread()->vault_.pending_nudge_types_); |
| + EXPECT_TRUE(CompareNudgeTypesBitSetToVault(model_types)); |
| syncer_thread()->RequestResume(); |
| interceptor.WaitForSyncShare(1, TimeDelta::FromSeconds(1)); |
| @@ -741,7 +781,7 @@ |
| // SyncerThread should be waiting again. Signal it to stop. |
| EXPECT_TRUE(syncer_thread()->Stop(2000)); |
| - EXPECT_TRUE(syncer_thread()->vault_.pending_nudge_types_.none()); |
| + EXPECT_TRUE(syncer_thread()->vault_.pending_nudge_types_.empty()); |
| } |
| TEST_F(SyncerThreadWithSyncerTest, NudgeWithDataTypesCoalesced) { |
| @@ -767,7 +807,7 @@ |
| syncer_thread()->NudgeSyncerWithDataTypes(100, |
| SyncerThread::kUnknown, |
| model_types); |
| - EXPECT_EQ(model_types, syncer_thread()->vault_.pending_nudge_types_); |
| + EXPECT_TRUE(CompareNudgeTypesBitSetToVault(model_types)); |
| model_types[syncable::BOOKMARKS] = false; |
| model_types[syncable::AUTOFILL] = true; |
| @@ -777,7 +817,7 @@ |
| // Reset BOOKMARKS for expectations. |
| model_types[syncable::BOOKMARKS] = true; |
| - EXPECT_EQ(model_types, syncer_thread()->vault_.pending_nudge_types_); |
| + EXPECT_TRUE(CompareNudgeTypesBitSetToVault(model_types)); |
| syncer_thread()->RequestResume(); |
| @@ -787,9 +827,90 @@ |
| // SyncerThread should be waiting again. Signal it to stop. |
| EXPECT_TRUE(syncer_thread()->Stop(2000)); |
| - EXPECT_TRUE(syncer_thread()->vault_.pending_nudge_types_.none()); |
| + EXPECT_TRUE(syncer_thread()->vault_.pending_nudge_types_.empty()); |
| } |
| +TEST_F(SyncerThreadWithSyncerTest, NudgeWithPayloads) { |
| + SyncShareIntercept interceptor; |
| + connection()->SetMidCommitObserver(&interceptor); |
| + // We don't want a poll to happen during this test (except the first one). |
| + PreventThreadFromPolling(); |
| + EXPECT_TRUE(syncer_thread()->Start()); |
| + metadb()->Open(); |
| + syncer_thread()->CreateSyncer(metadb()->name()); |
| + const TimeDelta poll_interval = TimeDelta::FromMinutes(5); |
| + interceptor.WaitForSyncShare(1, poll_interval + poll_interval); |
| + EXPECT_EQ(static_cast<unsigned int>(1), |
| + interceptor.times_sync_occured().size()); |
| + |
| + // The SyncerThread should be waiting for the poll now. Nudge it to sync |
| + // immediately (5ms). |
| + SyncSourceInfo::ModelTypeMap nudge_types; |
| + nudge_types[syncable::BOOKMARKS] = "test"; |
| + |
| + // Paused so we can verify the nudge types safely. |
| + syncer_thread()->RequestPause(); |
| + syncer_thread()->NudgeSyncerWithPayloads(5, |
| + SyncerThread::kUnknown, |
| + nudge_types); |
| + EXPECT_TRUE(CompareNudgeTypesToVault(nudge_types)); |
| + syncer_thread()->RequestResume(); |
| + |
| + interceptor.WaitForSyncShare(1, TimeDelta::FromSeconds(1)); |
| + EXPECT_EQ(static_cast<unsigned int>(2), |
| + interceptor.times_sync_occured().size()); |
| + |
| + // SyncerThread should be waiting again. Signal it to stop. |
| + EXPECT_TRUE(syncer_thread()->Stop(2000)); |
| + EXPECT_TRUE(syncer_thread()->vault_.pending_nudge_types_.empty()); |
| +} |
| + |
| +TEST_F(SyncerThreadWithSyncerTest, NudgeWithPayloadsCoalesced) { |
| + SyncShareIntercept interceptor; |
| + connection()->SetMidCommitObserver(&interceptor); |
| + // We don't want a poll to happen during this test (except the first one). |
| + PreventThreadFromPolling(); |
| + EXPECT_TRUE(syncer_thread()->Start()); |
| + metadb()->Open(); |
| + syncer_thread()->CreateSyncer(metadb()->name()); |
| + const TimeDelta poll_interval = TimeDelta::FromMinutes(5); |
| + interceptor.WaitForSyncShare(1, poll_interval + poll_interval); |
| + EXPECT_EQ(static_cast<unsigned int>(1), |
| + interceptor.times_sync_occured().size()); |
| + |
| + // The SyncerThread should be waiting for the poll now. Nudge it to sync |
| + // immediately (5ms). |
| + SyncSourceInfo::ModelTypeMap nudge_types; |
| + nudge_types[syncable::BOOKMARKS] = "books"; |
| + |
| + // Paused so we can verify the nudge types safely. |
| + syncer_thread()->RequestPause(); |
| + syncer_thread()->NudgeSyncerWithPayloads(100, |
| + SyncerThread::kUnknown, |
| + nudge_types); |
| + EXPECT_TRUE(CompareNudgeTypesToVault(nudge_types)); |
| + |
| + nudge_types.erase(syncable::BOOKMARKS); |
| + nudge_types[syncable::AUTOFILL] = "auto"; |
| + syncer_thread()->NudgeSyncerWithPayloads(0, |
| + SyncerThread::kUnknown, |
| + nudge_types); |
| + |
| + // Reset BOOKMARKS for expectations. |
| + nudge_types[syncable::BOOKMARKS] = "books"; |
| + EXPECT_TRUE(CompareNudgeTypesToVault(nudge_types)); |
| + |
| + syncer_thread()->RequestResume(); |
| + |
| + interceptor.WaitForSyncShare(1, TimeDelta::FromSeconds(1)); |
| + EXPECT_EQ(static_cast<unsigned int>(2), |
| + interceptor.times_sync_occured().size()); |
| + |
| + // SyncerThread should be waiting again. Signal it to stop. |
| + EXPECT_TRUE(syncer_thread()->Stop(2000)); |
| + EXPECT_TRUE(syncer_thread()->vault_.pending_nudge_types_.empty()); |
| +} |
| + |
| TEST_F(SyncerThreadWithSyncerTest, Throttling) { |
| SyncShareIntercept interceptor; |
| connection()->SetMidCommitObserver(&interceptor); |