| 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)
|
| @@ -169,6 +169,30 @@
|
| syncer_thread()->SetSyncerShortPollInterval(poll_interval);
|
| }
|
|
|
| + // Compare a provided datatype payload map to the datatype payloads stored
|
| + // in the SyncerThread vault.
|
| + bool ComparePayloadsToVault(const std::map<syncable::ModelType, std::string>&
|
| + lhs) {
|
| + for (size_t i = syncable::FIRST_REAL_MODEL_TYPE;
|
| + i < syncable::MODEL_TYPE_COUNT;
|
| + ++i) {
|
| + syncable::ModelType type = syncable::ModelTypeFromInt(i);
|
| + std::map<syncable::ModelType, std::string>::const_iterator payload =
|
| + lhs.find(type);
|
| + const std::map<syncable::ModelType, std::string>& vault_payloads =
|
| + syncer_thread()->vault_.datatype_payloads_;
|
| + if (payload != lhs.end()) {
|
| + if (vault_payloads.count(type) == 0 ||
|
| + payload->second != vault_payloads.find(type)->second) {
|
| + return false;
|
| + }
|
| + } else if (vault_payloads.count(type) > 0) {
|
| + return false;
|
| + }
|
| + }
|
| + return true;
|
| + }
|
| +
|
| private:
|
|
|
| virtual void OnSyncEngineEvent(const SyncEngineEvent& event) {
|
| @@ -468,7 +492,6 @@
|
| }
|
|
|
| {
|
| -
|
| // Now try with unsynced local items.
|
| context->set_last_snapshot(SessionSnapshotForTest(0, 1));
|
| bool continue_sync_cycle_param = false;
|
| @@ -512,7 +535,6 @@
|
|
|
| // Regression for exponential backoff reset when the syncer is nudged.
|
| {
|
| -
|
| context->set_last_snapshot(SessionSnapshotForTest(0, 1));
|
| bool continue_sync_cycle_param = false;
|
|
|
| @@ -790,6 +812,97 @@
|
| EXPECT_TRUE(syncer_thread()->vault_.pending_nudge_types_.none());
|
| }
|
|
|
| +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).
|
| + std::map<syncable::ModelType, std::string> payloads;
|
| + payloads[syncable::BOOKMARKS] = "test";
|
| +
|
| + // Paused so we can verify the nudge types safely.
|
| + syncer_thread()->RequestPause();
|
| + syncer_thread()->NudgeSyncerWithPayloads(5,
|
| + SyncerThread::kUnknown,
|
| + payloads);
|
| + EXPECT_TRUE(ComparePayloadsToVault(payloads));
|
| + syncable::ModelTypeBitSet model_types;
|
| + model_types[syncable::BOOKMARKS] = true;
|
| + EXPECT_EQ(model_types, syncer_thread()->vault_.pending_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_.none());
|
| + EXPECT_TRUE(syncer_thread()->vault_.datatype_payloads_.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).
|
| + std::map<syncable::ModelType, std::string> payloads;
|
| + payloads[syncable::BOOKMARKS] = "books";
|
| + syncable::ModelTypeBitSet model_types;
|
| + model_types[syncable::BOOKMARKS] = true;
|
| +
|
| + // Paused so we can verify the nudge types safely.
|
| + syncer_thread()->RequestPause();
|
| + syncer_thread()->NudgeSyncerWithPayloads(100,
|
| + SyncerThread::kUnknown,
|
| + payloads);
|
| + EXPECT_EQ(model_types, syncer_thread()->vault_.pending_nudge_types_);
|
| + EXPECT_TRUE(ComparePayloadsToVault(payloads));
|
| +
|
| + payloads.erase(syncable::BOOKMARKS);
|
| + payloads[syncable::AUTOFILL] = "auto";
|
| + model_types[syncable::AUTOFILL] = true;
|
| + syncer_thread()->NudgeSyncerWithPayloads(0,
|
| + SyncerThread::kUnknown,
|
| + payloads);
|
| +
|
| + // Reset BOOKMARKS for expectations.
|
| + payloads[syncable::BOOKMARKS] = "books";
|
| + EXPECT_EQ(model_types, syncer_thread()->vault_.pending_nudge_types_);
|
| + EXPECT_TRUE(ComparePayloadsToVault(payloads));
|
| +
|
| + 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_.none());
|
| + EXPECT_TRUE(syncer_thread()->vault_.datatype_payloads_.empty());
|
| +}
|
| +
|
| TEST_F(SyncerThreadWithSyncerTest, Throttling) {
|
| SyncShareIntercept interceptor;
|
| connection()->SetMidCommitObserver(&interceptor);
|
|
|